Nodejs String Sub String substrb(len)

Here you can find the source of substrb(len)

Method Source Code

String.prototype.substrb = function(len){
   var str1;/*from w  w w.ja va2s  .c  o  m*/
   if(this.lengthb() <= len)
   {
      return this;
   }
   for(var i = len/2; i < this.length; i++)
   {
      str1 = this.substr(0,i);
      if(str1.lengthb() == len)
      {
         return str1;
      }
      else if(str1.lengthb() > len)
      {
         return this.substr(0, i - 1);
      }
      else 
      {
         if(str1.lengthb() == len-1)
         {
            return str1;
         }
      }
   }
};

Related

  1. substr(begin, end)
    String.prototype.substr = function(begin, end) {
      if (end === null) { end = this.length;           }
      if (begin <  0)   { begin = this.length + begin; }
      if (end <= 0)     { end = this.length + end;     }
      if (begin < 1)    { begin = end - 1/begin;       }
      if (end < 1)      { end = begin + 1/end;         }
      return this.substring(begin, end);
    
  2. substr(start, length)
    String.prototype.substr = function(start, length) {
      if (start < 0) {
        start = start + this.length;
      if (!length) {
        length = this.length - start;
      var s = "";
      for (var i = start, len = this.length; i < start + length && i < len; i+) {
    ...
    
  3. substrCount(needle)
    String.prototype.substrCount = function(needle){
      var cnt = 0;
      for (var i=0;i<this.length;i++) {
      if (needle == this.substr(i,needle.length))
        cnt++;
      return cnt;
    };
    
  4. substrReplace(replaceWith, start, length)
    String.prototype.substrReplace = function(replaceWith, start, length){
      return this.replace(this.substring(start, (start+length)), replaceWith );
    };
    
  5. substrWoR(c)
    String.prototype.substrWoR = function(c){
      var n=1,o=0;
      while(o!=n){
        s=this.substr(0,c+(o=n)-1);
        n=s.split("\r").length;
      return s;
    
  6. substring(start, end)
    String.prototype.substring = function(start, end) {
      if (start < 0) {
        start = start + this.length;
      if (!end) {
        end = this.length;
      } else if (end < 0) {
        end = end + this.length;
      var s = "";
      for (var i = start, len = this.length; i < end && i < len; i++) {
        s += this[i];
      return s;
    };
    
  7. substrings()
    String.prototype.substrings = function () {
      subs = [];
      for(var i = 0; i < this.length; i++) {
        for( var j = i+1; j < this.length+1; j++) {
          subs.push(this.slice(i,j));
        };
      };
      return subs;
    };
    ...
    
  8. substrings()
    String.prototype.substrings = function(){
      var substrings = []
      for (var i=0; i<this.length; i++){
        for (var j=i+1; j<=this.length; j++){
          substrings.push(this.slice(i,j));
      return substrings;
    var str = 'cat';
    console.log(str.substrings());
    
  9. substrings()
    String.prototype.substrings = function () {
      var substrings = [];
      for (var start = 0; start < this.length; start++) {
        for (var len = 1; (start + len) <= this.length; len++) {
          substrings.push(this.slice(start, start + len));
      return substrings;
    };
    ...