[英]C++ Boost: Split function is_any_of()
我正在尝试在以下函数中使用boost/algorithm/string.hpp
中提供的split()
函数:
vector<std::string> splitString(string input, string pivot) { //Pivot: e.g., "##"
vector<string> splitInput; //Vector where the string is split and stored
split(splitInput,input,is_any_of(pivot),token_compress_on); //Split the string
return splitInput;
}
以下电话:
string hello = "Hieafds##addgaeg##adf#h";
vector<string> split = splitString(hello,"##"); //Split the string based on occurrences of "##"
将字符串分成"Hieafds" "addgaeg" "adf"
和"h"
。 但是我不希望字符串被单个#
拆分。 我认为问题在于is_any_of()
。
如何修改函数,以便只通过出现"##"
来拆分字符串?
你是对的,你必须使用is_any_of()
std::string input = "some##text";
std::vector<std::string> output;
split( output, input, is_any_of( "##" ) );
更新
但是,如果你想分成两个尖锐的,也许你必须使用正则表达式:
split_regex( output, input, regex( "##" ) );
看一下文档示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.