Hello, > Why is this not allowed? > > s := "hello" > s[0] = 'a' // compile error: cannot assign to s[0]
Because strings are immutable in Go. See https://golang.org/ref/spec#String_types You can construct a new string, or convert to byte slive and back. https://play.golang.org/p/0LvsxCCTM2G Regards, Harald -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200813131930.GA15579%40hweidner.de.