Write a Program to Remove All Characters From a String Except Alphabets

C++// C++ Programto remove all characters from a string except // alphabets #include <cctype> #include <iostream> #include <string> using namespace std; string remove_non_alphabets(string str) { string result = ""; for (char c : str) { if (isalpha(c)) { result += c; } } return result; } int main() { string str = "Gee$ksfor$geeks"; cout << "Alphabets only: " << remove_non_alphabets(str) << endl; return 0; }

Output

Alphabets only: Geeksforgeeks

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *