一旦我看到一个例子,这可能很简单,但是如何推广boost :: tokenizer或boost :: split来处理由多个字符组成的分隔符?
例如,使用“ _ _”,这些标准拆分解决方案似乎都不起作用:
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);
}
或
boost::split(result, myString, "___");
答案 0 :(得分:8)
boost::algorithm::split_regex( result, myString, regex( "___" ) ) ;
答案 1 :(得分:1)
您必须改为使用splitregex:http://www.daniweb.com/software-development/cpp/threads/118708/boostalgorithmsplit-with-string-delimeters
答案 2 :(得分:0)
非助推解决方案
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;
}