"Mel Smith" <
med_cuto...@aol.com> wrote on 15 jan 2014 in
comp.lang.javascript:
> Hi:
>
> I'm probably having a senior moment, but with IE8 as a test bed, I
> cannot seem to replace ' ' with an ordinary space character.
>
> e.g.,
>
> Let's say my input text string is:
>
> var mytext = " " + "Hello" + " " + "World" +
> " "
>
> Using IE8:
>
> var newtext = mytext.replace(" "," ") ;
>
> The above statement*works* in Chrome (i.e., it replaces ' '
> with an 'ordinary' space character
No, only the first one.
>
> But, in IE8 , these ' ' sequences are *not* replaced -- just
> ignored ??
IE11 does the same as chrome, are you sure about IE8?
> I need a 'kick-in-the-butt' please -- perhaps a real regex string that
> would work in all cases ?
Better always use regex with replace(),
and use the global switch if necessary:
var newtext = mytext.replace(/ /g,' ') ;
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)