您的位置:首页 > 其它

自己写的分割字符串的函数

2016-07-12 20:34 260 查看
void splitString(const std::string &str, const std::string &separator, std::vector<std::string> &retList)

{
string::size_type pos=0;
string::size_type newPos=0;
retList.clear();
while( (newPos= str.find(separator,pos)) != string::npos)
{
// if not empty sub str. (skip repetition of separator )
if(newPos-pos>0)
retList.push_back(str.substr(pos, newPos-pos));
// skip token
pos= newPos+separator.size();
}
// copy the last substr
if( pos<str.size() )
retList.push_back(str.substr(pos, str.size()-pos));

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: