Le Kevin dot com

photographic-poetic-musical horizon

Browsing Posts tagged ReplaceALL()

Most variables in JavaScript represent themselves internally as strings. The String class in JavaScript contains a number of handy methods, but many commonly-used functions which are available in other languages, such as the trim() function, are notably missing from JavaScript. Since strings are represented as JavaScript classes, it is possible to extend the functionality of [...]

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], “”); [...]