8

C++ Program to Remove all Characters in a String Except Alphabets

 2 years ago
source link: https://www.geeksforgeeks.org/videos/c-program-to-remove-all-characters-in-a-string-except-alphabets/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

C++ Program to Remove all Characters in a String Except Alphabets

C++ Program to Remove all Characters in a String Except Alphabets
Hello everyone. Welcome to Geeks Geeks. In
  • 21/06/2022

In this video, we will see a C++ program to remove all characters except alphabets. For this, a string can process the string word-by-word by checking for letters and then removing the current character from the letter thereby only retaining alphabets.

Example: Input string: V*id@e$oG!e#e%k)s Output: VideoGeeks

Here we use approaches for Remove all Characters in a String Except Alphabets: 1. For loop with If-else Condition

Algorithm:

Step 1: The program starts by declaring the string, which is to be processed. Step 2: It then declares the variable "a" which is used in the loop. The loop iterates through each character in the string and checks if it is an alphabet or not. Step 3: If it is an alphabet, then the character is appended to a new string that will be created after the loop ends. Step 4: Else, it will remove the character from the original string. Step 5: A new line of code is added after each iteration to show that we are still inside this loop and not at its end.

Apart from that, we will see the time complexity of the code, that is O(n*n). But as erase() may take O(n) in the worst case.

C++ Program to Remove all characters other than alphabets from a string: https://www.geeksforgeeks.org/remove-characters-alphabets-string/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK