Reputation: 6271
I've currently got the following to remove spaces and replace them with a hyphen. How can I go about replacing a space with a hyphen and a dot with nothing and keep it in the same variable?
url = url.replace(/\s/g, '-');
Upvotes: 1
Views: 2922
Reputation: 38
I use this:
// This little gadget does replace for all not just first occurence like the native javascript function.
String.prototype.replaceAll = function(strTarget, strSubString){
var strText = this;
var intIndexOfMatch = strText.indexOf(strTarget);
while (intIndexOfMatch != -1){
strText = strText.replace(strTarget, strSubString);
intIndexOfMatch = strText.indexOf(strTarget);
}
return(strText);
}
Upvotes: 2