Posted By

ptiswitz on 04/18/11


Tagged

trim


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

geek4evr


Add trim function to Javascript String Object


 / Published in: JavaScript
 

  1. String.prototype.ltrim = function() {
  2. return this.replace(/^\s+/, '');
  3. };
  4. String.prototype.rtrim = function() {
  5. return this.replace(/\s+$/, '');
  6. };
  7.  
  8. String.prototype.trim = function() {
  9. return this.ltrim().rtrim();
  10. };

Report this snippet  

You need to login to post a comment.