1 |
split string: default space
1
2
3
4
5
6string s = "This is, a test";
tokenizer<> tok(s);
for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg)
{
cout << *beg << "\n";
}split string: drop delimiter
1
2
3typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
boost::char_separator< char> sep("-;|");
tokenizer tokens(str, sep);split string: drop delimiter and keep delimiter
1
2
3typedef boost::tokenizer< boost::char_separator< char> > tokenizer;
boost::char_separator< char> sep("-;", "|", boost::keep_empty_tokens);
tokenizer tokens(str, sep);special kinds of tokenizer
1
2
3int offsets[] = {2,2,4}; //three segment length
offset_separator f(offsets, offsets+3);
tokenizer< offset_separator> tok(s,f);