Nodejs String Trimming Right trimEnd(trimStr)

Here you can find the source of trimEnd(trimStr)

Method Source Code

String.prototype.trimEnd = function (trimStr) {
    if (!trimStr) {
        return this;
    }/*from   w w w.  jav a  2s .  c  o m*/
    var temp = this;
    while (true) {
        if (temp.substr(temp.length - trimStr.length, trimStr.length) != trimStr) {
            break;
        }
        temp = temp.substr(0, temp.length - trimStr.length);
    }
    return temp;
}

Related

  1. rtrim(charlist)
    String.prototype.rtrim = function (charlist) {
      charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
      var re = new RegExp('^[' + charlist + ']+', 'g');
      return this.replace(re, '');
    };
    
  2. trimEnd()
    String.prototype.trimEnd = function() {
      for (var i=this.length-1; this.charAt(i) ==' '; i--) {
        this.substring(0, i);
      return this;
    };
    
  3. trimEnd(c)
    String.prototype.trimEnd=function(c)
        c = c?c:' ';
        var i=this.length-1;
        for(;i>=0 && this.charAt(i)==c;i--);
        return this.substring(0,i+1);
    var Utils = {
        getValues : function(dataSet)
    ...
    
  4. trimEnd(c)
    String.prototype.trimEnd=function(c)
        c = c?c:' ';
        var i=this.length-1;
        for(;i>=0 && this.charAt(i)==c;i--);
        return this.substring(0,i+1);
    
  5. trimEnd(s)
    String.prototype.trimEnd = function(s) {
        return this.replace(new RegExp(s + "+$", "gm"), "")
    
  6. trimRight()
    String.prototype.trimRight = String.prototype.trimRight || function() {
      return this.replace(/\s+$/,'');
    };
    
  7. trimRight()
    String.prototype.trimRight = String.prototype.trimRight || function () {
        return this.replace(/\s+$/g, "");
    };
    String.prototype.trimLeft = String.prototype.trimLeft || function () {
        return this.replace(/^\s+/g, "");
    };
    String.prototype.endsWith = String.prototype.endsWith || function(suffix) {
        return this.length ? this.lastIndexOf(suffix) === this.length - 1 : false;
    };
    ...
    
  8. trimRight(character)
    String.prototype.trimRight = function (character) {
      character = character || ' ';
      return this.replace(new RegExp('[' + character + ']+$'), "");
    };
    
  9. trimRight(charlist)
    String.prototype.trimRight = function(charlist) {
        "use strict";
        if (charlist === undefined)
            charlist = "\s";
        return this.replace(new RegExp("[" + charlist + "]+$"), "");
    };