the array to scan
the item to replace
the item to replace all instances of from with
the number of replacements
A new array without changing the contents of subject, or the original array if no match is found.
size_t changed = 0; assert("Hello Wörld".replace("o Wö", "o Wo", changed) == "Hello World"); assert(changed == 1); changed = 0; assert("Hello Wörld".replace("l", "h", changed) == "Hehho Wörhd"); import std.stdio : writeln; writeln(changed); assert(changed == 3);
Replace occurrences of from with to in subject in a new array. changed counts how many replacements took place.