Hi Giampero,
"Giampiero Gabbiani" <gi****************@libero.it> wrote in message
news:pa****************************@libero.it...
Is there a simple way to implement a strip algorithm on std::string using
STL?
I'm sure that it's possible to implement it using some transform, but my
knowledge of STL is POOR.
I am not sure what a 'strip algorithm' is...
To remove characters (e.g. blanks) from the beginning and the end of the
string (what I call 'trimming'), the following function can do:
/// Returns a string with leading/trailing characters of a set stripped
std::string trimmed
( std::string const& str ///< the original string
, char const* sepSet ///< C string with characters to be dropped
)
{
std::string::size_type const first = str.find_first_not_of(sepSet);
return ( first==std::string::npos )
? std::string()
: str.substr(first, str.find_last_not_of(sepSet)-first+1);
}
Sample usage:
string name = trimmed( userInput, " \t" ); // trip spaces and tabs
Not sure if this is what you were looking for...
Ivan
--
http://ivan.vecerina.com