Mike said:
What are some simple ways to trim (remove trailing or leading blanks)
a basic::string value? Outside of some clumsy and "brute-force" ways, I
can't seem to find one. TIA
You can use the method find_last_not_of() to find the last non-blank. Then,
use erase to chop off everything from that point. For someone sufficiently
brave, one could even imagine a one-liner:
str.erase( str.find_last_not_of( " " )+1 );
Try:
std::string a ( "xax " );
std::cout << "|" << a << "|\n";
a.erase( a.find_last_not_of( " " )+1 );
std::cout << "|" << a << "|\n";
However, that is a little tricky: arguing the correctness of the above in
the case that str is empty requires some thought.
The case of trimming a string at the front is left as an exercise
Best
Kai-Uwe Bux