Skip to content

Instantly share code, notes, and snippets.

@tadamatu
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadamatu/4399a511714c54cf9973 to your computer and use it in GitHub Desktop.
Save tadamatu/4399a511714c54cf9973 to your computer and use it in GitHub Desktop.
文字列をデリミタで分解しリスト化する関数
//[cocos2d-x]
//文字列をデリミタで分解しリスト化する関数
//str 対象文字列
//delim デリミタ
//Return 分解後リスト
std::list<std::string> split(std::string str, std::string delim) {
std::list<std::string> result;
long cutAt;
while( (cutAt = str.find_first_of(delim)) != str.npos ) {
if(cutAt > 0) {
result.push_back(trim(str.substr(0, cutAt)));
}
str = str.substr(cutAt + 1);
}
if(str.length() > 0) {
result.push_back(trim(str));
}
return result;
}
@tadamatu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment