Discussion: chopping strings
Afficher un message
Vieux 17/10/2007, 20h28   #3
Jim Langston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.


  Réponse avec citation
 
Page generated in 0,05296 seconds with 9 queries