Go - String
In Go, string is an immutable array of bytes. So if created, we can’t change its value. E.g.:
package main func main() { s := "Hello" s[0] = 'h' } The compiler will complain:
cannot assign to s[0]
To modify the content of a string, you could convert it to a byte array. But in fact, you do not operate on the original string, just a copy:
package main import "fmt" func main() { s := "Hello" b := []byte(s) b[0] = 'h' fmt.
[Read More]