The rune type in golang

RUNE is the same as INT32 in Golang, and is only commonly used for character conversion. The len() method in golang mainly evaluates the length of an array. The default storage string in Golang is UTF8 format, UTF8 uses variable length byte storage, English letter is a single byte storage, Chinese is 3 bytes storage, so -1 and -2 results are 16 and 15. []rune() and []rune() are two ways to convert utf8 into a four-byte int32 store, and then calculate the length of the int32 array.

-1 address := "this is shanghai" fmt.Println("len(address):",len(address)) -2 address := "this is shanghai" Fmt.println ("len(address):",len(address)) -3 addressThree :=" fmt.Println("len(address):",utf8.RuneCountInString(addressThree)) -4 Fmt.println (" Len (address):", Len ([]rune(addressThree))) -5 unicode.is (unicode.han, c) //

The results of

-1 
len(address): 16

-2
len(address): 15

-3
len(address): 5

-4
len(address): 5