This language bar is your friend. Select your favorite languages!

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

X2 = binary:replace(X, Y, Z, [global]).
string x2 = x.Replace(y, z);
import std.array;
auto x2 = x.replace(y,z);  
var x2 = x.replaceAll(y, z);
x2 = String.replace(x, y, z)
import "strings"
x2 := strings.Replace(x, y, z, -1)
import Data.List
allchanged [] _ _ = []
allchanged input from to = if isPrefixOf from input
  then to ++ allchanged (drop (length from) input) from to
  else head input : allchanged (tail input) from to

x2 = allchanged x y z
var x2 = x.replace(new RegExp(y, 'g'), z);
String x2 = x.replace(y, z);
x2 = x:gsub(y,z)
$x2 = str_replace($y, $z, $x);
x2 := StringReplace(x, y, z, [rfReplaceAll]);
substr($a, 5, 2) = "replacement text";
x2 = x.replace(y, z)
x2 = x.gsub(y, z)
let x2 = x.replace(&y, &z);

Do you know the best way to do this in your language ?
New implementation...

Idiom created by