Golang 字符串转 UTF-8 编码字节数组
可以使用 Go 语言的内置函数 []byte() 将字符串转换成 UTF-8 编码格式的字节数组。例如:
str := 'Hello, 世界'
bytes := []byte(str)
fmt.Println(bytes)
输出结果:
[72 101 108 108 111 44 32 228 184 150 231 149 140]
其中,'世界' 的 UTF-8 编码分别为 [228 184 150] 和 [231 149 140]。
原文地址: https://www.cveoy.top/t/topic/oOei 著作权归作者所有。请勿转载和采集!