fmtstring
func main() {
buf := make([]byte, 10)
buf[8] = 'A'
copy(buf, []byte("hello"))
fmt.Printf("cap(%d),len(%d)\n", cap(buf), len(buf))
fmt.Println("buf:", buf)
fmt.Printf("buf:%q\n", buf)
fmt.Println("buf:", string(buf))
str := string(buf)
str = str + " world"
fmt.Println(len(str)) // => 16
fmt.Println(str) // => helloA world
}
/* output
cap(10),len(10)
buf: [104 101 108 108 111 0 0 0 65 0]
buf:"hello\x00\x00\x00A\x00"
buf: helloA
16
helloA world
*/
fmtstring(buf)helloAascii码[104 101 108 108 111 0 0 0 65 0]
%qhello\x00\x00\x00A\x00string
str + " world"str
fmt