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.
- 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
- Splitting a Numeric String
- Count special palindromes in a String
- Move all special char to the end of the String
- Reverse a string without affecting special characters
- Check if a string can be rearranged to form special palindrome
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Extract maximum numeric value from a given string | Set 1 (General approach)
- Python Regex to extract maximum numeric value from a string
- Program to count vowels, consonant, digits and special characters in string.
- Split the string into substrings using delimiter
- How to split a string in C/C++, Python and Java?
- Check if given string can be split into four distinct strings