Remove in javascript string

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 ";
var result = test.remove(12,3);

Related posts:


comments powered by Disqus