void split(std::string& s, std::string& delim,std::vector< std::string >* ret)
{
size_t last = 0;
size_t index=s.find_first_of(delim,last);
while (index!=std::string::npos)
{
ret->push_back(s.substr(last,index-last));
last=index+1;
index=s.find_first_of(delim,last);
}
if (index-last>0)
{
ret->push_back(s.substr(last,index-last));
}
{
size_t last = 0;
size_t index=s.find_first_of(delim,last);
while (index!=std::string::npos)
{
ret->push_back(s.substr(last,index-last));
last=index+1;
index=s.find_first_of(delim,last);
}
if (index-last>0)
{
ret->push_back(s.substr(last,index-last));
}
}
http://www.cppblog.com/sssa2000/archive/2008/11/05/66042.aspx
本文介绍了一个使用C++实现的字符串拆分函数,该函数能够将一个字符串根据指定的分隔符进行拆分,并将结果保存在一个字符串向量中。通过这个简单的函数,可以方便地处理各种字符串操作任务。
1228

被折叠的 条评论
为什么被折叠?



