setCharAt method

void setCharAt(
  1. int index,
  2. String char
)

Sets the character at the specified index.

index the index char the new character

Implementation

void setCharAt(int index, String char) {
  if (char.length != 1) {
    throw InvalidArgumentException('Must be a single character');
  }

  String current = _buffer.toString();
  if (index < 0 || index >= current.length) {
    throw RangeError('Index out of range: $index');
  }

  String before = current.substring(0, index);
  String after = current.substring(index + 1);

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