天天看点

Go的[]rune 和 []byte的区别

Go的[]rune 和 []byte的区别

  []rune 和 []byte源码

// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8

// rune is an alias for int32 and is equivalent to int32 in all ways. It is
// used, by convention, to distinguish character values from integer values.      

  原来是 ​

​byte​

​​ 表示一个字节,​

​rune​

​ 表示四个字节,那么就可以得出了结论了,来看一段代码,使用中文字符串

  1、[]rune (四个字节)

  2、[]byte (一个字节)