text: Remove all characters other than alphabets from string | CPP program to remove all the characters other then alphabets ; function to remove characters and print new string ; Finding the character whose ASCII value fall under this range ; erase function to erase the character ; driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void removeSpecialCharacter ( string s ) { for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] < ' A ' s [ i ] > ' Z ' && s [ i ] < ' a ' s [ i ] > ' z ' ) { s . erase ( i , 1 ) ; i -- ; } } cout << s ; } int main ( ) { string s = " $ Gee * k ; s . . fo , ▁ r ' Ge ^ eks ? " ; removeSpecialCharacter ( s ) ; return 0 ; }