分隔符,我用下面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