Global.String.prototype.group (interval, str, ignoreWhiteSpace)
function inserts a string every number of characters

  • Parameter Int:
    number of characters after which insertion should take place
  • Parameter String:
    string to be inserted
  • Parameter Boolean:
    definitely insert at each interval position
  • Returns
    String resulting string
Sourcecode in /home/hannes/helma/modules/core/String.js:
401:   String.prototype.group = function(interval, str, ignoreWhiteSpace) {
402:       if (!interval || interval < 1)
403:           interval = 20;
404:       if (!str || this.length < interval)
405:           return this;
406:       res.push();
407:       for (var i=0; i<this.length; i=i+interval) {
408:           var strPart = this.substring(i, i+interval);
409:           res.write(strPart);
410:          if (ignoreWhiteSpace == true || 
411:              (strPart.length == interval && !/\s/g.test(strPart))) {
412:              res.write(str);
413:          }
414:      }
415:      return res.pop();
416:  }