您的位置:首页 > 其它

函数备份:按照指定的分隔符,将字符串进行切分

2011-03-01 09:47 316 查看
vector<string>Preprocess:: mySplit(string s,set<string> stopwords)
{
vector<string> wordCollection;
trim(s," ");

int nPosBegin=0;
int nPosEnd=s.find(',',nPosBegin);
while(nPosEnd!=string::npos)
{
string temp=s.substr(nPosBegin,nPosEnd-nPosBegin);
trim(temp," ");
if(temp!="")
{
wordCollection.push_back(temp);
}

nPosBegin=s.find_first_not_of(',',nPosEnd);
if(nPosBegin==string::npos)
{
nPosEnd=string::npos;
}
else
{
nPosEnd=s.find(',',nPosBegin);

}

}
if(nPosBegin!=string::npos&&nPosEnd==string::npos)//结尾缺少分割号,添加该词
{
string temp=s.substr(nPosBegin,s.size()-nPosBegin);
trim(temp," ");
if(temp!="")
{
wordCollection.push_back(temp);
}

}

return wordCollection;

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