Given a string str, divide the string into three parts one containing a numeric part, one containing alphabetic and one containing special characters.
Input : geeks01for02geeks03!!! Output :geeksforgeeks 010203 !!! Here str = "Geeks01for02Geeks03!!!", we scan every character and append in res1, res2 and res3 string accordingly. Input : **Docoding123456789everyday## Output :Docodingeveryday 123456789 **##
- Calculate the length of the string.
- Scan each every character(ch) of a string one by one
- if (ch is a digit) then append it in res1 string.
- else if (ch is alphabet) append in string res2.
- else append in string res3.
- Print the all the strings, we will have one string containing numeric part, other non numeric part and last one contain special characters.
geeksforgeeks 010203 $$!@!!
Time complexity of above solution is O(n) where n is the length of the string.
This article is contributed by Rishabh Jain. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Count Uppercase, Lowercase, special character and numeric values
- Parsing String of symbols to Expression
- Print all the palindromic permutations of given string in alphabetic order
- Find the largest Alphabetic character present in the string
- Splitting a Numeric String
- Move all special char to the end of the String
- Count special palindromes in a String
- Reverse a string without affecting special characters
- Check if a string can be rearranged to form special palindrome
- Python Regex to extract maximum numeric value from a string
- Extract maximum numeric value from a given string | Set 1 (General approach)
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Program to count vowels, consonant, digits and special characters in string.
- Minimum circular rotations to obtain a given numeric string by avoiding a set of given strings
- Split the given string into Odds: Digit DP