package main
import "fmt"
func main() {
s := "中国"
s1 := []rune(s)
fmt.Println(len(s)) // 6
fmt.Println(len(s1)) // 2
fmt.Printf("%x, %x\n", s1[0], s1[1]) // 4e2d, 56fd
}
len函数计算的是字符串底层的字节数,字符串s用utf8编码后是6个字节。
rune是int32的同义词,表示一个unicode码点。
中的unicode码点为4e2d,国的unicode码点为56fd。