Nodejs String Sub String substr(begin, end)

Here you can find the source of substr(begin, end)

Method Source Code

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);
}

Related

  1. subStrings()
    String.prototype.subStrings = function(){
      const substringArray = [];
      for (var i = 0; i < this.length; i++){
        for (var j = i; j < this.length; j++){
          let substring = this.slice(i,j+1);
          if (!substringArray.includes(substring)){
            substringArray.push(substring);
      return substringArray;
    console.log("abc".subStrings());
    
  2. subStrs()
    String.prototype.subStrs = function() {
      var output = [];
      for( var i = 0; i < this.length; i++ ) {
        for( var j = 0; j <= this.length; j++ ) {
          if(i < j) {
            output.push(this.substring(i,j));
        };
      };
    ...
    
  3. subst(replacements)
    String.prototype.subst = function(replacements) {
        return this.replace(/%[A-Z][A-Z0-9_]+%/g, function (placeholder) {
            return placeholder in replacements ? replacements[placeholder] : placeholder;
        });
    };
    
  4. subst(replacements)
    String.prototype.subst = function (replacements) {
        "use strict";
        return this.replace(/%[A-Z][A-Z0-9_]+%/g, function (placeholder) {
            return placeholder in replacements ? replacements[placeholder] : placeholder;
        });
    };
    
  5. substitute(object, regexp)
    String.prototype.substitute = function(object, regexp){
      return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
        if (match.charAt(0) == '\\') return match.slice(1);
        return (object[name] !== null) ? object[name] : '';
      });
    };
    
  6. 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+) {
    ...
    
  7. 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;
    };
    
  8. substrReplace(replaceWith, start, length)
    String.prototype.substrReplace = function(replaceWith, start, length){
      return this.replace(this.substring(start, (start+length)), replaceWith );
    };
    
  9. 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;