Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string.replace()

Status
Not open for further replies.

adiMasher

Programmer
Aug 31, 2001
144
US
Okay, this seems a little weird, but I get different performance from netscape to MS

MS replaces all instances of the searched string and Netscape only replaces the first instance

How do I make netscape replace all instances in StringVar.replace("searchstring", "replaceStr");

Thank you,

Martin If the sky is blue and the Sun is yellow.... Why isn't the air Green?
 
Ah well no longer do I post the question that I remember that you can use Regular expressions

Code:
stringVar = stringVar.replace(/test/g, "TEST");

use regex and use the "g" option for global

If the sky is blue and the Sun is yellow.... Why isn't the air Green?
 
may also want to use gi for global ignore case depending on the value you are replacing ---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top