In C++, what’s an easy way to turn:
This std::string
\t\tHELLO WORLD\r\nHELLO\t\nWORLD \t
Into:
HELLOWORLDHELLOWORLD
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simple combination of
std::remove_ifandstd::string::erase.Not totally safe version
For safer version replace
::isspacewith(Include all relevant headers)
For a version that works with alternative character types replace
<char>with<ElementType>or whatever your templated character type is. You can of course also replace the locale with a different one. If you do that, beware to avoid the inefficiency of recreating the locale facet too many times.In C++11 you can make the safer version into a lambda with: