Posted by skoch on 6. Februar 2009
/* enhance string prototype */
String.prototype.leftTrim = function ()
{
return ( this.replace ( /^s+/, "" ) );
};
String.prototype.rightTrim = function ()
{
return ( this.replace ( /s+$/, "" ) );
};
// combines "leftTrim" and "rightTrim";
String.prototype.Trim = function ()
{
return ( this.replace ( /s+$/, "" ).replace ( /^s+/, "" ) );
};
// makes space sequences to single spaces
String.prototype.superTrim = function ()
{
return ( this.replace ( /s+/g, " " ).replace ( /s+$/, "" ).replace ( /^s+/, "" ) );
};
// removes all spaces from a string
String.prototype.removeWhiteSpaces = function ()
{
return ( this.replace ( /s+/g, "" ) );
};
Filed under: JavaScript
Leave a Reply
You must be logged in to post a comment.