Nodejs String Trim Trim( aimStr )

Here you can find the source of Trim( aimStr )

Method Source Code

String.prototype.Trim = function( aimStr )
{
    var str = this;
    var re = My.RegExp.InvolvedCharsRegExp;
    var reStart, reEnd;
    if ( aimStr )
    {/*from ww w  .j  av  a2  s.  co m*/
        aimStr = aimStr.replace( re, '\\$1' );
        reStart = new RegExp( '^(' + aimStr + ')+' );
        reEnd = new RegExp( '(' + aimStr + ')+$' );
    }
    else
    { 
        reStart = /^\s+/;
        reEnd = /\s+$/;
    }
    str = str.replace( reStart, '' ).replace( reEnd, '' );
    return str;
};

Related

  1. trimToPx(length)
    String.prototype.trimToPx = function(length)
        var tmp = this;
        var trimmed = this;
        if (tmp.visualLength() > length)
            trimmed += "...";
            while (trimmed.visualLength() > length)
                tmp = tmp.substring(0, tmp.length-1);
                trimmed = tmp + "...";
        return trimmed;
    
  2. trimTrailZeroes()
    String.prototype.trimTrailZeroes = function() {
        return this.replace(/(.\d*?)0+$/, "$1").replace(/\.$/, "");
    };
    
  3. trim_(str)
    var trim_ = function (str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    };
    
  4. trimfast()
    String.prototype.trimfast = function() {
      var  str = this.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = this.length;
      while (ws.test(this.charAt(--i)));
      return str.slice(0, i + 1);
    };
    (function($){
      $.fn.trimval = function() {
    ...
    
  5. trimj()
    String.prototype.trim  = jCube.String.trim  = function () {
      return this.replace( /^\s+|\s+$|^\n+|\n+$|^\t+|\t+$/g, "");
    
  6. Trim()
    String.prototype.Trim = function(){
      return this.replace(/(^\s*)|(\s*$)/g, "");
    };
    
  7. Trim()
    String.prototype.Trim = function() {
      return this.lTrim().rTrim();
    };
    
  8. Trim()
    String.prototype.Trim = function(){
      return this.replace(/(^\s*)|(\s*$)/g,"");
    };
    
  9. Trim()
    String.prototype.Trim = function() 
      var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);  
      return (m == null) ? "" : m[1];