Posted By

letosword on 09/17/09


Tagged

trim


Versions (?)

Trim function


 / Published in: JavaScript
 

  1. String prototype.trim = function() {
  2. a = this.replace(/^\s+/, '');
  3. return a.replace(/\s+$/, '');
  4. };

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: iroybot on September 17, 2009

just a matter of taste, but I like jQuery.trim('string'); but that might have something to do with laziness ;)

Posted By: iroybot on September 17, 2009

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 )

You need to login to post a comment.