Home > Article > Backend Development > golang rune a few bytes
rune is used to distinguish character values and integer values Represents a UTF-8 character. When you need to process Chinese, Japanese or other compound characters, you need to use the rune type. The rune type is equivalent to the int32 type. byte is equivalent to int8, which is one byte in length, commonly used to process ascii characters
rune is equivalent to int32, which is 4 bytes in length, and is commonly used to process unicode or utf- 8 characters
##Example:package main
import (
"fmt"
)
func main() {
str := "你好 world"
fmt.Printf("len(str):%d\n", len(str)) //返回len(str):12
}
The return value is 12 because Chinese characters occupy 2 bytes under unicode and utf-8 encoding It occupies 3 bytes, and golang's default encoding is exactly utf-8.
The above is the detailed content of golang rune a few bytes. For more information, please follow other related articles on the PHP Chinese website!