Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 10
    This one has a performance issue in cases where the source string is large and there are many occurences of the string to be replaced. string::replace() would be called many times which causes lots of string copies. See my solution which addresses that problem. Commented Apr 21, 2015 at 6:44
  • 1
    Nit picking ahead: by address => by reference. Whether it's an address or not is an implementation detail. Commented May 18, 2015 at 16:16
  • 2
    You should actually check if from string is empty, otherwise an endless loop will occur. Commented Sep 5, 2015 at 2:23
  • This is the most concise and elegant solution. Bolsters my faith in the STL: deceptively simple. Commented Feb 17 at 22:01