Javascript string method prototype ex. Remove(), ReplaceAll(), Trim()


String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, “”); };

String.prototype.replaceAll = function(item,replacewith) {
var s = this;
while (s.indexOf(item) >= 0)
s = s.replace(item, replacewith);
return s;
}

String.prototype.remove = function(item) { return this.replaceAll(item, “”); }

function removeTags(str) {
var tags = ["<B>", "<b>", "</b>", "</B>", "&nbsp;"];
for (var i in tags)
str = str.remove(tags[i], “”);
return str;
}

, , , ,

  1. No comments yet.
(will not be published)