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 ; Store only valid characters ; driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void removeSpecialCharacter ( string s ) { int j = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( ( s [ i ] >= ' A ' && s [ i ] <= ' Z ' ) || ( s [ i ] >= ' a ' && s [ i ] <= ' z ' ) ) { s [ j ] = s [ i ] ; j ++ ; } } cout << s . substr ( 0 , j ) ; } int main ( ) { string s = " $ Gee * k ; s . . fo , ▁ r ' Ge ^ eks ? " ; removeSpecialCharacter ( s ) ; return 0 ; }