A str can't be changed in place: s[i] reads the i-th char but can't be assigned. Build a
new string instead.
Wrong#
fn main() {
var s = "cat"
s[0] = 'b'
print(s)
}Fixed#
fn main() {
var s = "cat"
s = "b" + s[1..3]
print(s)
}Common causes#
- Editing a string char by char: use
replace, slices and+, or work ons.chars()and join withstr(cs).