[Boost-users] string boost::split

369 views
Skip to first unread message

Dmitry Teslenko

unread,
Apr 14, 2008, 12:19:48 PM4/14/08
to boost...@lists.boost.org
Hello!
For example I want to split string with single char '\t' delimeter.
According to docs this can be done this way:
std::vector<std::string> options;
std::string sep;
sep += '\t';
boost::split(options, line, boost::is_any_of(sep));

But if I want to use double tab as a delimiter? Is there an
alternative to boost::is_any_of like "boost::just_what_i_say"
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Markus Svilans

unread,
Apr 14, 2008, 2:00:30 PM4/14/08
to boost...@lists.boost.org
Hi Dmitry,

Check out regex_token_iterator in the Boost Regex documentation. It will
let you use any kind of delimiter you want, including regular expressions.

Also, split() can split the string on multiple delimiters, so it would
work on one or more tab characters. However, if you want it to split
only on double tabs, and not one or three or more, then it wouldn't be
suitable. For that, regex_token_iterator would be best.

Regards,
Markus.

Surya Kiran Gullapalli

unread,
Apr 15, 2008, 5:27:30 AM4/15/08
to boost...@lists.boost.org
take a look at
string_split_iterator

Surya

Pavol Droba

unread,
Apr 15, 2008, 10:49:01 AM4/15/08
to boost...@lists.boost.org
Hi,

Dmitry Teslenko wrote:
> Hello!
> For example I want to split string with single char '\t' delimeter.
> According to docs this can be done this way:
> std::vector<std::string> options;
> std::string sep;
> sep += '\t';
> boost::split(options, line, boost::is_any_of(sep));
>
> But if I want to use double tab as a delimiter? Is there an
> alternative to boost::is_any_of like "boost::just_what_i_say"

You can use boost::split_iterator with first_finder. Or if you prefer
split-like interface, have a look at iter_split.

Here is an example

std::vector<std::string> options;
std::string sep;
sep += '\t';

boost::iter_split(options, line, boost::first_finder("\t\t"));

Regards,
Pavol.

Reply all
Reply to author
Forward
0 new messages