分隔符,我用下面tokening,但不知道该如何与包括它的分隔符。记号化字符串,包括在C++
void Tokenize(const string str, vector<string>& tokens, const string& delimiters)
{
int startpos = 0;
int pos = str.find_first_of(delimiters, startpos);
string strTemp;
while (string::npos != pos || string::npos != startpos)
{
strTemp = str.substr(startpos, pos - startpos);
tokens.push_back(strTemp.substr(0, strTemp.length()));
startpos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, startpos);
}
}
1为Boost.Tokenizer提及 –
我编辑了m y发布包含所有的功能。 我看到你做了什么,但分隔符将是一个字符串,字符串中的每个字符将是一个分隔符。通过像这样“!\ n”个 因此,一个逗号,句号,感叹号和新的生产线将被推入载体为好,但是不占空间。通过这种方式,我可以将矢量加入并在矢量项之间使用空格并重新构建字符串。 – Jeremiah
逗号,句号,感叹号和包括空格在内的新行将成为分隔符。对不起,想清楚。 – Jeremiah