javascript: trim string

by prettyscripts on 2008-03-27 11:00:41

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.
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 />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)