/ Published in: JavaScript
Expand |
Embed | Plain Text
String prototype.trim = function() { a = this.replace(/^\s+/, ''); return a.replace(/\s+$/, ''); };
Comments
Subscribe to comments
You need to login to post a comment.

just a matter of taste, but I like jQuery.trim('string'); but that might have something to do with laziness ;)
PS: you might want to check out PHPJS.org's version which takes a lot of UTF-8 derivatives of the whitespaces character, which makes it more failsafe ( http://phpjs.org/functions/trim )