PrestwoodBoards Knowledgebase: portal.prestwood.com/ASPSuite/kb/

store.prestwood.com

  From the October 2015 Issue of Prestwood eMag
 
JavaScript and AJAX:
replaceAll
 
Posted 10/19/2007 on 10/19/2007 and updated 6/18/2008
JavaScript Code Snippet:

KB100700

Implements replaceAll in javascript. This is achieved using prototype.js

Syntax Example:

Add this between the head tags (replace [[ with < and ]] with >):

[[script type="text/javascript" src="prototype.js"]] [[/script]]

Here's the code (replace [[ with < and ]] with >):

[[script type="text/javascript"]]
// define your replace all function like this 
String.prototype.replaceAll=function(s1, s2) 
{return this.split(s1).join(s2)}; 
// use your replaceAll function like this
var replacedText = text2replace.replaceAll("-what to replace-",
		" -with what to replace- "); 
[[/script]]
Code Contributed By bhavyait:
Visit Profile
store.prestwood.com
Copyright (C) Prestwood IT Solutions.
All Rights Reserved.
Printed 9/28/2020