感觉有用,就记下来了:
vector<std::string> LiteracyCollectionLayer::split( std::string str,std::string separator )
{
vector<string> result;
int cutAt;
while( (cutAt = str.find_first_of(separator)) != str.npos )
{
if(cutAt > 0)
{
result.push_back(str.substr(0, cutAt));
}
str = str.substr(cutAt + 1);
}
if(str.length() > 0)
{
result.push_back(str);
}
return result;
}
用法就很简单了:
vector<std::string> vec_str_num= split(“好@无@聊”,"@");
注意: 在ios平台上,不要用‘&’这个符号,会出问题。