443,505 Members | 1,206 Online
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

# remove spaces from begin a string

 P: n/a im made subj like this: inline bool isnt_space (int sp) { return (::isspace (sp)) ? false : true; } str.erase ( std.begin () , std::find_if ( str.begin(), str.end(), isnt_space) ); How i can use std for better away? Can i invert result of the ::isspace by means of bind2nd? -- www.andr.mobi Dec 27 '07 #1
5 Replies

 P: n/a On 27 ΔΕΛ, 13:59, Andrew Wingorodov

 P: n/a Andrew Wingorodov

 P: n/a Daniel T. bool isnt_space (int sp) { return (::isspace (sp)) ? false : true; } inline bool isnt_space( int sp ) { return !::isspace( sp ); } OK Try this: str.erase( str.begin(), find_if( str.begin(), str.end(), not1( ptr_fun( &::isspace ) ) ) ); str.erase( str.begin(), find_if( str.begin(), str.end(), isnt_space ) ); 10x -- www.andr.mobi Dec 28 '07 #4

 P: n/a Andrew Wingorodov wrote: im made subj like this: inline bool isnt_space (int sp) { return (::isspace (sp)) ? false : true; } str.erase ( std.begin () , std::find_if ( str.begin(), str.end(), isnt_space) ); How i can use std for better away? Can i invert result of the ::isspace by means of bind2nd? This is what I use to trim spaces from the beginning and end of a std::string: std::string trim( const std::string& text, const char TrimChar = ' ' ); 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); } This will remove the trim char (defaults to space, but you can make it anything) from the beginning and end of a string. -- Jim Langston ta*******@rocketmail.com Dec 28 '07 #5

 P: n/a "Jim Langston"

### This discussion thread is closed

Replies have been disabled for this discussion.