slice method

String slice(
  1. int start, [
  2. int end = -1
])

Returns a new substring containing all characters between start (inclusive) and end (inclusive). If end is omitted, it is being set to lastIndex.

print('awesomeString'.slice(0,6)); // awesome
print('awesomeString'.slice(7)); // String

Implementation

String slice(int start, [int end = -1]) {
  start = start < 0 ? start + length : start;
  end = end < 0 ? end + length : end;

  RangeError.checkValidRange(start, end, length);

  return substring(start, end + 1);
}