safeSubstring method

String safeSubstring(
  1. int startIndex,
  2. int endIndex
)

Safely substrings the string, if the string length is not enough, return the original string.

Example:

'12345678'.safeSubString(0, 20); // '12345678'

Implementation

String safeSubstring(int startIndex, int endIndex) {
  if (startIndex < 0) startIndex = 0;
  if (endIndex > length) endIndex = length;
  return substring(startIndex, endIndex);
}