String.replace 
Author Message
 String.replace

how can i replace all substrinmgs in a string

sample:

AxxxxAxxxxA -> BxxxxBxxxxB

AxxxxAxxxxA.replace("A","B") returns: BxxxxAxxxxA :-(



Fri, 25 Jul 2003 20:57:41 GMT  
 String.replace

"AxxxxAxxxxA".replace(/A/g,"B")

Quote:

> how can i replace all substrinmgs in a string

> sample:

> AxxxxAxxxxA -> BxxxxBxxxxB

> AxxxxAxxxxA.replace("A","B") returns: BxxxxAxxxxA :-(

--

        Martin Honnen
        http://javascript.faqts.com/
        http://home.t-online.de/home/martin.honnen/jsgoddies.html



Fri, 25 Jul 2003 21:02:48 GMT  
 String.replace
var a="AxxxAxxxA";
while (a.indexOf("A")>0)
    a.replace("A","B");
Quote:

> how can i replace all substrinmgs in a string

> sample:

> AxxxxAxxxxA -> BxxxxBxxxxB

> AxxxxAxxxxA.replace("A","B") returns: BxxxxAxxxxA :-(



Fri, 25 Jul 2003 23:34:16 GMT  
 String.replace
yezzz, or:

var s = "A"
var e = new RegExp(s,"g")
alert("AxxAxxA".replace(e,"B"));

if "A" is a variable

thanx!


Quote:

> "AxxxxAxxxxA".replace(/A/g,"B")

> > how can i replace all substrinmgs in a string

> > sample:

> > AxxxxAxxxxA -> BxxxxBxxxxB

> > AxxxxAxxxxA.replace("A","B") returns: BxxxxAxxxxA :-(

> --

> Martin Honnen
> http://javascript.faqts.com/
> http://home.t-online.de/home/martin.honnen/jsgoddies.html



Sat, 26 Jul 2003 03:51:13 GMT  
 String.replace
this works too, but i use a regexp object now

thanx


Quote:
> var a="AxxxAxxxA";
> while (a.indexOf("A")>0)
>     a.replace("A","B");


> > how can i replace all substrinmgs in a string

> > sample:

> > AxxxxAxxxxA -> BxxxxBxxxxB

> > AxxxxAxxxxA.replace("A","B") returns: BxxxxAxxxxA :-(



Sat, 26 Jul 2003 03:52:13 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help with string.replace

2. String.replace() -- No Regular Expresions?

3. regular expressions with string.replace

4. string.replace - help!

5. String Replace

6. string.replace()

7. String.replace() question

8. problem with string.replace

9. String.replace() inside class method, help.....

10. Replacing a string within a string?

11. "replace" can't replace all string in a long string?

12. Replace string

 

 
Powered by phpBB® Forum Software