Strings are always modelled as immutable (atleast in heigher level languages python/java/javascript/Scala/Objective-C).
So any string operations like concatenation, replacements always returns a new string which contains intended value, whereas the original string will still be same.
If you just want to clobber all of the instances of a substring out of a string without using regex you can using:
var replacestring = "A B B C D"
const oldstring = "B";
const newstring = "E";
while (replacestring.indexOf(oldstring) > -1) {
replacestring = replacestring.replace(oldstring, newstring);
}
//result: "A E E C D"
Isn't string.replace returning a value, rather than modifying the source string?
So if you wanted to modify variableABC, you'd need to do this:
var variableABC = "A B C";
variableABC = variableABC.replace('B', 'D') //output: 'A D C'
Source: Stackoverflow.com