Computer Store
store.prestwood.com
-Collapse +Expand
JavaScript
Search JavaScript Group:

Advanced
-Collapse +Expand JavaScript Store

Prestwood eMagazine

August Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...JavaScript a...   Print This     
  From the October 2015 Issue of Prestwood eMag
 
JavaScript and AJAX:
replaceAll
 
Posted 13 years ago on 10/19/2007 and updated 6/18/2008
JavaScript Code Snippet:
 A flashcard from our JavaScript Flashcards Library
 A code snippet from our JavaScript Code Snippets Page

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]]

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P187A1
Enter key:
Code Contributed By bhavyait:
Visit Profile

 KB Article #100700 Counter
13649
Since 4/2/2008


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech