replaceRange method

String replaceRange(
  1. int start,
  2. int end,
  3. String replacement
)

Replace range of characters.

Implementation

String replaceRange(int start, int end, String replacement) {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  if (this!.isEmpty) {
    return '';
  }
  if (start < 0) {
    throw ArgumentError('start: $start');
  }
  if (end < 0) {
    throw ArgumentError('end: $end');
  }
  if (start > end) {
    throw ArgumentError('start: $start, end: $end');
  }
  if (start > this!.length) {
    throw ArgumentError('start: $start, length: ${this!.length}');
  }
  if (end > this!.length) {
    throw ArgumentError('end: $end, length: ${this!.length}');
  }
  return this!.substring(0, start) + replacement + this!.substring(end);
}