delete method

StringBuilder delete(
  1. int start,
  2. int end
)

Deletes characters from the specified range.

start the starting index (inclusive) end the ending index (exclusive) Returns this StringBuilder for method chaining

Implementation

StringBuilder delete(int start, int end) {
  String current = _buffer.toString();
  if (start < 0 || end > current.length || start > end) {
    throw RangeError('Invalid range: $start to $end');
  }

  String before = current.substring(0, start);
  String after = current.substring(end);

  _buffer.clear();
  _buffer.write(before);
  _buffer.write(after);

  return this;
}