insert method
Inserts a string at the specified index.
index
the index at which to insert
str
the string to insert
Returns this StringBuilder for method chaining
Implementation
StringBuilder insert(int index, String str) {
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);
_buffer.clear();
_buffer.write(before);
_buffer.write(str);
_buffer.write(after);
return this;
}