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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count Uppercase, Lowercase, special character and numeric values
- Parsing String of symbols to Expression
- Find the largest Alphabetic character present in the string
- Print all the palindromic permutations of given string in alphabetic order
- How to find index of any Currency Symbols in a given string
- Split the string into minimum parts such that each part is in the another 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 Primes : Digit DP
- How to split a string in C/C++, Python and Java?
- Split the given string into Odds: Digit DP
- Split the string into substrings using delimiter