replaceCharAt method
Replaces the character at the specified index
in the string with newChar
.
Returns a new string with the character at index
replaced by newChar
.
Throws a RangeError if index
is out of bounds.
Example:
'hello'.replaceCharAt(1, 'a'); // returns 'hallo'
Implementation
String replaceCharAt(int index, String newChar) {
return substring(0, index) + newChar + substring(index + 1);
}