Strings In Depth6 / 17
Up next

Strings are immutable; []byte is not

package main

import "fmt"

func main() {
	s := "hello"
	// a string can't be mutated; convert to []byte to change it
	b := []byte(s)
	b[0] = 'H'
	// convert back to a fresh string
	fmt.Println(string(b))
}
What you're solving

edit text via a byte slice