Global.String.prototype.embody (limit, clipping, delimiter)
breaks up a string into two parts called head and tail at the given position don't apply this to HTML, i.e. use stripTags() in advance

  • Parameter Number:
    number of charactrers or of segments separated by the delimiter
  • Parameter String:
    pre-/suffix to be pre-/appended to shortened string
  • Parameter String:
    delimiter
  • Returns
    Object containing head and tail properties
Sourcecode in /home/hannes/helma/modules/core/String.js:
343:   String.prototype.embody = function(limit, clipping, delimiter) {
344:      if (typeof limit == "string")
345:         limit = parseInt(limit, 10);
346:      var result = {head: this, tail: String.NULL};
347:      if (!limit || limit < 1)
348:         return result;
349:      if (!delimiter || delimiter == String.NULL)
350:         result.head= this.substring(0, limit);
351:      else {
352:        var re = new RegExp ("(" + delimiter + "+)");
353:        result.head = this.split(re, 2*limit - 1).join(String.NULL);
354:     }
355:     if (result.head != this) {
356:        result.tail = this.substring(result.head.length).trim();
357:        if (result.tail) {
358:           if (clipping == null)
359:              clipping = "...";
360:           result.head = result.head.trim() + clipping;
361:           result.tail = clipping + result.tail;
362:        }
363:     }
364:     return result;
365:  }