What's the best way to trim std::string
Posted
by Milan Babuškov
on Stack Overflow
See other posts from Stack Overflow
or by Milan Babuškov
Published on 2008-10-19T19:23:07Z
Indexed on
2010/03/30
17:53 UTC
Read the original article
Hit count: 403
I'm currently using the following code to right-trim all the std::strings in my programs:
std::string s;
s.erase(s.find_last_not_of(" \n\r\t")+1);
It works fine, but I wonder if there are some end-cases where it might fail?
Of course, answers with elegant alternatives and also left-trim solution are welcome.
© Stack Overflow or respective owner