Remove Characters Except Alphabets - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 26, 2020

Remove Characters Except Alphabets

C++ PROGRAM TO REMOVE CHARACTERS EXCEPT ALPHABETS  IN A STRING

Sample Test Case    :    Enter the String : 3He*ll#o!

Sample Output    :  Hello 

CODE

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string line;
    cout<<"Enter a String : ";
    getline(cin,line);
    for(int i=0;i<line.size();++i)
    {
        if(!((line[i]>='a'&& line[i]<='z')||(line[i]>='A'&&line[i]<='Z')))
        {
            line[i]='\0';
        }
    }
    cout<<"Output String :"<<line;
    return 0;
}

No comments:

Post a Comment