K
kilik3000
How do you do a global replace in a string without using a regex?
For example,
"ABBA".replace("B", "") returns -> "ABA" // I'd like this to be a
global replace
"ABBA".replace(/B/g, "") returns -> "AA" // this works correctly but
requires a regex
The reason I ask is that I'd like to have a function that just takes a
single character as an argument and then passes that character to
replace. So the "B" in my example would be a param/variable.
If I have to use a regex is there a way to parameterize it?
var b = "B";
"ABBA".replace(/b/g, "")
Does not work.
-Thx
For example,
"ABBA".replace("B", "") returns -> "ABA" // I'd like this to be a
global replace
"ABBA".replace(/B/g, "") returns -> "AA" // this works correctly but
requires a regex
The reason I ask is that I'd like to have a function that just takes a
single character as an argument and then passes that character to
replace. So the "B" in my example would be a param/variable.
If I have to use a regex is there a way to parameterize it?
var b = "B";
"ABBA".replace(/b/g, "")
Does not work.
-Thx