Trim() functionality in JavaScript

Below is are the trim(), ltrim() and rtrim() functionality for strings in Javascript:

/********** String Trim Utilites *********************/
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function () {
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function () {
    return this.replace(/\s+$/, "");
}

0 comments

Posts a comment

Popular Posts

 
© Old - Pinal Bhatt's Blog
From the desk of Pinal Bhatt | www.PBDesk.com
Back to top