Re: chopping strings
"djm" <djmlog103@gmail.com> wrote in message
news:1192633612.268469.31450@q5g2000prf.googlegrou ps.com...
> hello everyone. ive a string with a blank space at the start
> for eg:
> string str=" c++ rocks!";
> how can i chop of that blank space of the string and display?
> thanks
This is what I use.
std::string trim( const std::string& text, const char TrimChar = ' ' )
{
std::string::size_type First = text.find_first_not_of(TrimChar);
if ( First == std::string::npos )
return "";
return text.substr( First, text.find_last_not_of(TrimChar) - First +
1);
}
Note it will trim any spaces (or specified character) from both the front
and end of the string.
|