November 02, 2009
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 - StartindexAnd some test code:
//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;
};
var test = "test string test ";
alert(test);
var result = test.remove(12,3);
alert(result);
Comments
comments powered by Disqus