slice method

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

Creates a slice of string from start up to, but not including, end.

var string = '__justkawal';

//It slices the string and returns modified string
var slicedString = string.slice(2); // slicedString = 'justkawal';

Implementation

String slice(int start, [int? end]) {
  var length = this.length;
  if (length <= 0) {
    return '';
  }
  end ??= length;

  if (start < 0) {
    start = -start > length ? 0 : (length + start);
  }
  if (end > length) {
    end = length;
  }
  if (end < 0) {
    end += length;
  }
  length = start > end ? 0 : (end - start).zeroFillRightShift(0);
  start = start.zeroFillRightShift(0);

  var index = -1;
  var result = '';
  while (++index < length) {
    result += this[index + start];
  }
  return result;
}