Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2007-02-16 06:16:23


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::vector<std::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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net