SolutionCottage.com
Posted  11 Sep 2009 - 22:16:32

Category: JavaScript


Javascript replace all instances of a string

Issue:
You have a string and want to replace certain contents in it with something else. When using something like ...

string.replace("replace this", "with this");


... this you note that only the first instance gets replaced.

Solution:


You can use a regular expression global replace instead. Something along these lines:

string.replace(/replace this/g, "with this");








0 comments:








© SolutionCottage 2008-2011 9/24/2017 12:59:25 PM