Javascript String trim( ext )

Description

Javascript String trim( ext )

String.prototype.trim = function( ext )
{
 var chars = [//from  w w  w. j  a v a 2  s.  c om
  " ", "\t", "\n", "\r"
 ];
 
 var s = this.copy();
 
 if( arguments.length > 0 ){
  for( var i in ext ){
   chars.push( ext[i] );
  }
 }
 
 while( chars.indexOf( s.charAt( 0 ) ) != -1 ){
  s = s.substring( 1, s.length );
 }
 while( chars.indexOf( s.charAt( s.length-1 ) ) != -1 ){
  s = s.substring( 0, s.length-1 );
 }
 return s;
};



PreviousNext

Related