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

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;

}

你可能感兴趣的:(字符串)