Skip to content

Instantly share code, notes, and snippets.

@tadamatu
Created July 25, 2015 01:46
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/e18063aa519b07bde76f to your computer and use it in GitHub Desktop.
Save tadamatu/e18063aa519b07bde76f to your computer and use it in GitHub Desktop.
文字列の置換
//[cocos2d-x]
//文字列の置換
//target 対象文字列
//from 検索する文字列(置換される文字列)
//to 置換する文字列
//Return 置換後文字列
std::string stringReplace(const std::string target, const std::string from, const std::string to) {
std::string result = target;
std::string::size_type pos = 0;
while(pos = result.find(from, pos), pos != std::string::npos) {
result.replace(pos, from.length(), to);
pos += to.length();
}
return result;
}
@tadamatu
Copy link
Author

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