Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ programming code to remove all characters from string except alphabets

#include <bits/stdc++.h>
using namespace std;
// function to remove characters and
// print new string
void removeSpecialCharacter(string s) {
    for (int i = 0; i < s.size(); i++) {
        // Finding the character whose
        // ASCII value fall under this
        // range
        if (s[i] < 'A' || s[i] > 'Z' && s[i] < 'a' || s[i] > 'z') {
            // erase function to erase
            // the character
            s.erase(i, 1);
            i--;
        }
    }
    cout << s;
}
// driver code
int main() {
    string s = "P*re;p..ins't^a?";
    removeSpecialCharacter(s);
    return 0;
}
Source by prepinsta.com #
 
PREVIOUS NEXT
Tagged: #programming #code #remove #characters #string #alphabets
ADD COMMENT
Topic
Name
9+4 =