Monday, May 2, 2011

C++ Replace String

void replace(string &str, string s1, string s2) {
  while (str.find(s1) != string::npos) {
    int pos = str.find(s1);
    str.insert(pos, s2);
    pos = str.find(s1);
    str.erase(pos, s1.length());
  }
}

No comments:

Post a Comment