Skip to content

Instantly share code, notes, and snippets.

@nMustaki
Created June 12, 2012 14:04
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 nMustaki/2917728 to your computer and use it in GitHub Desktop.
Save nMustaki/2917728 to your computer and use it in GitHub Desktop.
quick multiple replace in string
#include <string>
#include <iostream>
#include <algorithm>
#include <list>
std::string& bulk_replace(std::string& s, std::string &src, char dest)
{
std::string::iterator it;
for (it = src.begin(); it != src.end(); ++it)
std::replace(s.begin(), s.end(), (*it), dest);
return s;
}
int main(int argc, char **argv)
{
std::string key = "Héllo World";
std::string chars = "ÈÉÊËèéê";
bulk_replace(key, chars, 'e');
std::cout << key << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment