C ++ / Boost splits a string into multiple characters

This is probably very simple as soon as I see an example, but how to generalize boost :: tokenizer or boost :: split to work with separators consisting of more than one character?

For example, with "__", none of these standard separation solutions 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, "___"); 
+4
source share
3 answers
 boost::algorithm::split_regex( result, myString, regex( "___" ) ) ; 
+8
source

No boost solution

 vector<string> split(const string &s, const string &delim){ vector<string> result; int start = 0; int end = 0; while(end!=string::npos){ end = s.find(delim, start); result.push_back(s.substr(start, end-start)); start = end + delim.length(); } return result; } 
0
source

All Articles