removeLast method

String removeLast(
  1. int count
)

Removes the last count characters from the string.

Returns an empty string if count equals or exceeds the string length.

Example:

'hello'.removeLast(2)   // 'hel'
'hi'.removeLast(5)      // ''
'abc'.removeLast(0)     // 'abc'

Implementation

String removeLast(int count) {
  if (count < 0) { return this; }
  if (count > length) { return ''; }
  return substring(0, length - count);
}