substr function

String substr(
  1. String str,
  2. int start, [
  3. int? length
])

Implementation

String substr(String str, int start, [int? length]) {
  if (start < 0) {
    start = str.length + start;
  }
  if (start < 0) {
    start = 0;
  }
  if (start > str.length) {
    start = str.length;
  }
  var end = length == null
      ? str.length
      : start + length > str.length
          ? str.length
          : start + length;
  return str.substring(start, end);
}