Re: String.Replace Not Working

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Dr J R Stockton wrote on 10 aug 2008 in microsoft.public.scripting.jscript:

A consequence is that one can write
S = "1,2,3,4,5,6,7,8,9".replace(/,/g, "\t")
to generate a string longer (as displayed) than its generator.

There must be more ingenious examples of using replace on a string
literal.

var s = "1,2,3,4,5,6,7,8,9";
s = s.replace(/,/g,'\n');
s = s.replace(/\d/g,function(x,y){return y+': '+y*y});
alert(s)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.