maxChars method

String? maxChars(
  1. int n
)

Trims the String to have maximum n characters.

Example

String foo = 'esentis';
String newFoo = foo.maxChars(3); // 'esen';

Implementation

String? maxChars(int n) {
  if (this.isBlank || n >= this.length) {
    return this;
  }

  if (n <= 0) {
    return '';
  }

  return this.substring(0, n);
}