cocos2d-x实现split分割字符串

#include <string>

#include <vector>

 

/************************************************************************/

/* 函数功能:分隔字符串                                                                     */

/************************************************************************/

static  vector<string>  split(const string& src, const string& separator)

{  

vector<string>dest;

string str = src;

string substring;

string::size_type start = 0, index;

    

do

{

index = str.find_first_of(separator,start);

if (index != string::npos)

{    

substring = str.substr(start,index-start);

dest.push_back(substring);

start = str.find_first_not_of(separator,index);

if (start == string::npos) return dest;

}

}while(index != string::npos);

    

//the last token

substring = str.substr(start);

dest.push_back(substring);

    

return dest;

}

posted @ 2012-09-07 14:06  六界剑仙  阅读(775)  评论(0编辑  收藏  举报