Your Ad Here

Posted By

szsk on 08/02/06


Tagged

javascript String


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

luman
Navegante
wizard04


string_trim


 / Published in: JavaScript
 

  1. String.prototype.trim = function( charlist ) {
  2. var chars = charlist || "\\s";
  3. return this.replace(
  4. new RegExp( "^[" + chars + "]+|[" + chars + "]+$", "g" ), "" );
  5. }
  6. String.prototype.ltrim = function( charlist ) {
  7. var chars = charlist || "\\s";
  8. return this.replace(
  9. new RegExp( "^[" + chars + "]+", "g" ), "" );
  10. }
  11. String.prototype.rtrim = function( charlist ) {
  12. var chars = charlist || "\\s";
  13. return this.replace(
  14. new RegExp( "[" + chars + "]+$", "g" ), "" );
  15. }

Report this snippet  

You need to login to post a comment.