0

input without space

hi everyone, i want to make input for name and phone number but i want the input not have to use space like for example myname66777 and i want the output become myname 66777. can anyone tell me how to do this? :)

5th Oct 2018, 3:28 AM
Yoaraci
Yoaraci - avatar
2 Réponses
+ 4
The first thing which comes to mind would be <regex>. std::string str = "HatsyRei0123456789"; std::string name = std::regex_replace(str, std::regex("[0-9]"), ""); std::string num = std::regex_replace(str, std::regex("[a-zA-Z]"), ""); std::cout << name << " " << num; For some reason, this works half of the time on Code Playground. The other half gives me "Compilation Error". Desktop site giving me connection issues currently, so I can't test it. However, I can confirm that it's running fine on CodeChef, OnlineGDB, Cpp.sh, etc.
5th Oct 2018, 4:11 AM
Hatsy Rei
Hatsy Rei - avatar
0
could check it easily by regular expression and show error `/\s/.test(name)`
5th Oct 2018, 8:41 PM
Sergei No
Sergei No - avatar