replaceAtIndex method
Adds a replacement
character at index
of the String
.
Example
String foo = 'hello';
String replaced = foo.replaceAtIndex(index:2,replacement:''); // returns 'helo';
Implementation
String replaceAtIndex({required int index, required String replacement}) {
if (this.isBlank) {
return this;
}
if (index > this.length) {
return this;
}
if (index < 0) {
return this;
}
return '${this.substring(0, index)}$replacement${this.substring(index + 1, this.length)}';
}