javascript: trim string

by prettyscripts on 2008-03-27 11:00:41 • Leave a comment »

javascriptcode

javascript does not come with a trim function. you need to write your own.

Code:

function trim(str) {
    return str.replace(/^\s+|\s+$/g, '');
}

for other variations, check this.

Tags: javascript, string, trim

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)