Remove in javascript string

November 02, 2009 Javascript Regular expressions Nils Snippet
Yet another extension to the String object in Javascript submitted by Nils Forsman. This one adds the function of removing a part of a string, given a startposition and the length of the part to remove:
//A - Startindex
//B - Length
String.prototype.remove = function(A, B) {
var s = '';
if (A > 0)
s = this.substring(0, A);
if (A + B < this.length)
s += this.substring(A + B, this.length);
return s;
};
And some test code:
var test = "test string test ";
alert(test);
var result = test.remove(12,3);
alert(result);

Related posts: