File: Demo.js

Recommend this page to a friend!
  Classes of martin barker  >  String Multi Replace  >  Demo.js  >  Download  
File: Demo.js
Role: Example script
Content type: text/plain
Description: example of how to use.
Class: String Multi Replace
Replace multiple expressions in a single string
Author: By
Last change:
Date: 6 years ago
Size: 502 bytes
 

Contents

Class file image Download
// setup a stirng
var test = "hello world";

// this shows that the original String.replace method still works
var original = test.replace("world","martin");
// original == "hello martin";

// this replaces based on index to array1[0] will become array2[0]
var newStr = test.replace(["hello", "world"], ["bye", "martin"]);
// newStr == "bye martin"

// this replaces all first values with the second value
var newStr2 = test.replace(["hello", "world"], "bye");
// newStr2 == "bye bye";