Click to See Complete Forum and Search --> : js:replace dont work:(


pelegk1
08-13-2003, 06:19 AM
why this isnt working :
x="abcdeee";
x.replace("e","z");
alert("1:"+x);

even whne i do this :

x="abcdeee";
x.replace("z","r");
alert("2:"+x);

doesnt work!!!why???

Jeff Mott
08-13-2003, 06:41 AM
The replace method does not modify the string it works on, but rather returns a new string. So...

x = x.replace("e","z");

Fang
08-13-2003, 06:47 AM
The first argument has to be a regular expression.

re = /e/gi;
str = "abcdeee";
newstr=str.replace(re, "z");
document.write(newstr);

The result is "abcdzzz"