C ++ /升压上的多个字符分割字符串 [英] C++/Boost split a string on more than one character
本文介绍了C ++ /升压上的多个字符分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是大概真的简单,一旦我看到一个例子,但我怎么概括的boost ::标记生成器或升压::分开来处理由多个字符分隔的?
例如,用的 _ 的_,无论这些标准分裂的解决方案似乎工作:
的boost ::标记生成器<提高:: escaped_list_separator<串GT; >
TK(MyString的,提振:: escaped_list_separator<串GT;(,____,\\));
的std ::矢量<串GT;结果;
对于(字符串tmpString:TK){
result.push_back(tmpString);
}
或
的boost ::分(结果,MyString的,___);
解决方案
的boost ::算法:: split_regex(结果,MyString的,正则表达式(___));
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, "___");
解决方案
boost::algorithm::split_regex( result, myString, regex( "___" ) ) ;
这篇关于C ++ /升压上的多个字符分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文