input without space | Sololearn: Learn to code for FREE!

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? :)

10/5/2018 3:28:35 AM

Yoaraci

2 Answers

New Answer

+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.

0

could check it easily by regular expression and show error `/\s/.test(name)`