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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace function for string object

Status
Not open for further replies.

sodakotahusker

Programmer
Mar 15, 2001
601
does this statement only change first occurrence?

var string1 = "hello:dolly:"
var string2 = string1.replace(":"," ");

That is what I am seeing.

If that is true then there should be an additional paramter to indicate all occurences should be replaced????
 
Yeah, you need to add the global indicator and change your syntax a bit, like this:
Code:
var string1 = "hello:dolly:"
var string2 = string1.replace(/:/g," ");

that should do it

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Thanks! Does it not seem strange that someone one write a 900 page book about javascript and leave out that little details? - especially since other programming languages change all occurrences by default.
 
you must have the wrong book - it's conspicuously mentioned in O'Reilly's "Javascript: The Definitive Guide"


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top