lastChars method

String lastChars(
  1. int n
)

Get the last n characters of a string.

Returns the full string if its length is less than n.

Implementation

String lastChars(int n) {
  // Handle invalid length.
  if (n <= 0) return '';
  // If requested length is greater than or equal to string length, return the whole string.
  if (n >= length) return this;
  // Return the last n characters.
  return substring(length - n);
}