Skip to content Skip to sidebar Skip to footer

Replacing Word In A String

I want to replace a word in a string with another word but code does not work. NOTE: Preserve the case of the original word when you are replacing it. For example, if you mean

Solution 1:

You're over-complicating things my friend. Just use replace() http://www.w3schools.com/jsref/jsref_replace.asp


Solution 2:

Works great all but the fact your calling the function myReplace when your defined function name is replace


Solution 3:

You can use the replace() method like below:

"A quick brown fox jumped over the lazy dog".replace("jumped", "leaped");

Explained here


Post a Comment for "Replacing Word In A String"