View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
Given string str, divide the string into three parts one containing a numeric part, one containing alphabetic, and one containing special characters.
Examples:
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 **##
Steps :
- Calculate the length of the string.
- Scan 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 all the strings, we will have one string containing a numeric part, other non-numeric part, and the last one contains special characters.
Implementation:
C++
#include
using
namespace
std;
void
splitString[string str]
{
string alpha, num, special;
for
[
int
i=0; i=
'A'
&& str[i] =
'a'
&& str[i]