strLimit method

String strLimit(
  1. int limit, [
  2. String ending = '...'
])

Implementation

String strLimit(int limit, [String ending = '...']) {
  if (length > limit) {
    return substring(0, limit) + ending;
  }
  return this;

  // example:
  // strLimit('Hello World', 5); // returns 'Hello...'
  // strLimit('Hello World', 5, '!'); // returns 'Hello!'
}