Last active
April 23, 2016 12:28
-
-
Save liuml07/5671365 to your computer and use it in GitHub Desktop.
The missing std::string::replace_all(str, from, to)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size_t replace_all(string &str, const string &from, const string &to) { | |
size_t count = 0; | |
size_t pos = 0; | |
while ((pos = str.find(from, pos)) != string:npos) { | |
str.replace(pos, from.length(), to); | |
pos += to.length(); | |
++count; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment