Search code examples
c++stringparsingboosttokenize

C++/Boost split a string on more than one character


This is probably really simple once I see an example, but how do I generalize boost::tokenizer or boost::split to deal with separators consisting of more than one character?

For example, with "__", neither of these standard splitting solutions seems to work :

boost::tokenizer<boost::escaped_list_separator<string> > 
        tk(myString, boost::escaped_list_separator<string>("", "____", "\""));
std::vector<string> result;
for (string tmpString : tk) {
    result.push_back(tmpString);
}

or

boost::split(result, myString, "___");

Solution

  • boost::algorithm::split_regex( result, myString, regex( "___" ) ) ;