How to replace all spaces in a string
Pure Javascript, without regular expression:
var result = replaceSpacesText.split(" ").join("");
takes care of multiple white spaces and replaces it for a single character
myString.replace(/\s+/g, "-")
http://jsfiddle.net/aC5ZW/340/
var result = replaceSpace.replace(/ /g, ";");
Here, / /g
is a regex (regular expression). The flag g
means global. It causes all matches to be replaced.