String.prototype.trim=function(){
var _argument = arguments[0] || " ";
var _re= new RegExp("(^" _argument "*)|(" _argument "*$)","g"); // Case sensitive
return this.replace(_re,"");
}
String.prototype.ltrim=function(){
var _argument = arguments[0] || " ";
var _re= new RegExp("(^" _argument "*)","g");
return this.replace(_re,"");
}
String.prototype.rtrim=function(){
var _argument = arguments[0] || " ";
var _re= new RegExp("(" _argument "*$)","g");
return this.replace(_re,"") ;
}
string.trim(",") means to delete the "," on the left and right ends of string. If trim takes no parameters, the default is to delete both spaces at the end.
More powerful than the previous trim!