
Hi, abir basak wrote:
Hi, I want to tokenize a string based on one or multiple space or tab
std::string s = " a b c d \te "; std::vectorstd::string tokens; boost::algorithm::split(tokens,s,boost::algorithm::is_any_of(" \t"),token_compress_on); copy(tokens.begin(),tokens.end(),ostream_iterator<string>(cout,"\n"));
This gives more or less correct result, except it does not remove space/ tab from begin /end.
There is a reason to this. When the split bahaves this way, it si possible to recreate a original string. Also, there are situations when the empty token at the begin/end has a meaning.
It can be done like trim(s); and then call the above.
This is a standard solution.
But is there any other way it can be done in split itself ?
No, this behaviour is intentional. Best Regards, Pavol.