Tech Sharing Blog

Web, Tech, Tips, Download Blog…

Advertisement

Trim a string in Javascript

By David on June 13, 2009


Trim is a good features when you try to delete the space at the left most, right most or both the left most and right most of the string. The following trim function is ultilize the javascript Regular expression for the trim function


Left Trim

function ltrim(str){

    return str.replace(/^s+/, ”);

}


Right Trim

function rtrim(str) {

    return str.replace(/s+$/, ”);

}


All trim

function alltrim(str) {

    return str.replace(/^s+|s+$/g, ”);

}


Popularity: 1% [?]



Related posts:

  1. Form validation not allow chinese cheractor the following example use the javascript regular express to validate...

  2. HTML table word wrap I created a table to display a link which consist...

  3. Attaching event in both MSIE and FF with Javascript Most of the developer who working in MS platform will...

  4. URL Hidden Tricks to check page’s last update Check the page’s last update date Go to any web...


Comments

No Responses to “Trim a string in Javascript”

Write a Comment

CommentLuv Enabled
SEO Powered by Platinum SEO from Techblissonline