C++ String Exercises: Remove all special characters from a given string
22. Remove All Special Characters from a String
Write a C++ program to remove all special characters from a given string.
List of special characters: ., !, @, #, $, %, ^, &, \, *, (, )
Sample Data:
("abcd $ js# @acde$") -> “abcd js acde”
Sample Solution-1:
C++ Code:
Sample Output:
Original string: abcd $ js# @acde$ New string after removing the special characters from the said string: abcd js acde
Flowchart:

Sample Solution-2:
C++ Code:
Sample Output:
Original string: abcd $ js# @acde$ New string after removing the special characters from the said string: abcd js acde
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program to filter out non-alphanumeric characters from a string and print the cleaned result.
- Write a C++ program that reads a string and removes all punctuation and symbols, leaving only letters and spaces.
- Write a C++ program to iterate over a string and build a new string that excludes all special characters.
- Write a C++ program to process a string and output it with special characters stripped out using ASCII checks.
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous C++ Exercise: Check if a string is a subsequence of another string.
Next C++ Exercise: Count the number of unique characters of two strings.What is the difficulty level of this exercise?