Remove all occurrences of a character from a string using STL
Given a string S and a character C, the task is to remove all the occurrences of the character C from the given string.
Input:vS = “GFG IS FUN”, C = ‘F’
Output:GG IS UN
Removing all occurrences of the character ‘F’ modifies S to “GG IS UN”.
Therefore, the required output is GG IS UN
Input: S = “PLEASE REMOVE THE SPACES”, C = ‘ ‘
Removing all occurrences of the character ‘ ‘ modifies S to “GG IS UN”.
S.erase(remove(S.begin(), S.end(), c), S.end())
Below is the implementation of the above approach:
String Before: GFG is Fun String After: GG is un
Time Complexity: O(N2)
Auxiliary Space: O(1)