Nodejs String Split splitAndTrim($delimiter, $limit)

Here you can find the source of splitAndTrim($delimiter, $limit)

Method Source Code

String.prototype.splitAndTrim = function ($delimiter, $limit) {
   var $ss = this.split($delimiter, $limit);
   for (var $i = 0; $i < $ss.length; $i++) {
      $ss[$i] = $ss[$i].trim();//from  w  w w  . j  a va 2  s  . c  o  m
   }
   return $ss;
};

Related

  1. split(separator, nbr)
    String.prototype.split = function(separator, nbr) {
      var results = [];
      var pt = "";
      var ct = 0;
      for (var i = 0, len = this.length; i < len; i++) {
        if (this[i] == separator) {
          results.push(pt);
          pt = ""; ct++;
          if (nbr && ct >= nbr) {
    ...
    
  2. split140chars()
    String.prototype.split140chars = function(){
      const results = [ "" ];
      for(let line of this.split(/[\r\n]/)){
        if(results[0].length + line.length + 1 > 140){
          results.unshift("");
        if(results[0].length > 0) results[0] += "\n";
        results[0] += line;
      return results.reverse();
    };
    
  3. split2(a, b)
    String.prototype.split2 = function(a, b) {
      var lines = this.split(a);
        for (var i = 0; i < lines.length; i++)
            lines.splice.apply(lines, [i, 1].concat(lines[i].split(b)));
        return lines;
    };
    String.prototype.lines = function() {
      return this.split2('\r', '\n');
    };
    ...
    
  4. split2(s)
    String.prototype.split2 = function(s) {
        var rg = this.split(s);
        if ((rg.length == 1) && (rg[0] === ''))
            return [];
        return rg;
    };
    
  5. splitANArguments()
    String.prototype.splitANArguments = function(){
      var r = [];
      var t = '';
      var isQuote = false;
      for(var i = 0; i < this.length; i++){
        if(!isQuote && this.charAt(i) == ' '){
          r.push(t);
          t = '';
        else{
          if(this.charAt(i) == '"'){
            t += this.charAt(i);
            isQuote = !isQuote;
          else{
            t += this.charAt(i);
      r.push(t);
      return r;
    
  6. splitBy()
    String.prototype.splitBy = function(){
      return splitAll(this, Array.slice(arguments));
    };
    
  7. splitBy(delimiter)
    String.prototype.splitBy = function (delimiter) {
      var 
        delimiterPATTERN = '(' + delimiter + ')', 
        delimiterRE = new RegExp(delimiterPATTERN, 'g');
      return this.split(delimiterRE).reduce((chunks, item) => {
        if (item.match(delimiterRE)){
          chunks.push(item)
        } else {
          chunks[chunks.length - 1] += item
    ...
    
  8. splitByNum(num)
    String.prototype.splitByNum = function(num){
      return this.split('').reduce((a,b)=>{
        const alen = a[a.length-1]
        alen.length%2==0&&alen.length!=0?a.push(b):a[a.length-1] = alen+b+''
        return a
      },[''])
    
  9. splitChars(len)
    String.prototype.splitChars = function(len) {
    a = this.split('');
    res = [];
    i = 0;
    [].forEach.call(a, function(b, c) {
      if (c % len == 0) {
        i++;
        res.push([])
      res[i - 1].push(b);
    });
    f = [];
    res.forEach(function(d) {
      f.push(d.join(''));
      return true;
    });
    g =f.join('\n');
    return g;
    };