Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

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

#include 
using namespace std;
int main()
{
    //Initializing variable.
    char str[100];
    int i, j;
    
    //Accepting input.
    cout<<"Enter a string : ";
    gets(str);

    //Iterating each character and removing non alphabetical characters.
    for(i = 0; str[i] != ''; ++i)
    {
        while (!( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '') )
        {
            for(j = i; str[j] != ''; ++j)
            {
                str[j] = str[j+1];
            }
            str[j] = ''; 
        }
    }
    //Printing output.
    cout<<"After removing non alphabetical characters the string is :";
    puts(str);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: set to vector c++ 
Cpp :: cpprestsdk send file 
Cpp :: cuda shared array 
Cpp :: Round 1 Confusion codechef solution in c++ 
Cpp :: pthread c++ example with output 
Cpp :: c ++ The output should be (abc),(def),(ghw) 
Cpp :: progress indicator raytracer 
Cpp :: c++ calling variable constructor 
Cpp :: in built function to find MSB in cpp 
Cpp :: varint index 
Cpp :: subtraction of a 2d matrix in c++ 
Cpp :: c++ online 
Cpp :: c++ anti debugging 
Cpp :: gdb get return value of function 
Cpp :: turbo c++ easy programs 
Cpp :: get range sum 
Cpp :: how to find common divisors of two numbers in cpp 
Cpp :: transpose function example in c++ 
Cpp :: overload operator object function call 
Cpp :: create dynamic variable c++ 
Cpp :: Polycarp found a rectangular table consisting of n rows and m columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": codeforces solution 
Cpp :: CPP Find options passed from command line 
Cpp :: delay without blocking 
Cpp :: C++ Single Line Comments 
Cpp :: numpy array scalar addition 
Cpp :: C++ Rectangular Form 
Cpp :: c ++ loop 
Cpp :: how to insert variable into string c++ 
Cpp :: c+ - Dormir en millisecondes 
Cpp :: c++ how to iterate through 2d array in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =