golang之rune类型:
字符串中的每一个元素叫做“字符”,在遍历或者单个获取字符串元素时可以获得字符
Go语言的字符有以下两种:
一种是byte 类型,代表了 ASCII 码的一个字符。byte等价于uint8类型
另一种是 rune 类型,代表一个Unicode字符,当需要处理中文、日文或者其他复合字符时,则需要用到 rune 类型。rune 类型等价于 int32 类型
// 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.
type rune = int32
关于rune的几个点:https://juejin.cn/post/7068726981159829541
rune的使用场景:https://learnku.com/articles/23411/the-difference-between-rune-and-byte-of-go
int的各个单位大小:https://clickhouse.com/docs/en/sql-reference/data-types/int-uint
unicode和ascii的区别主要体现在:
1.编码范围不同
ASCII的编码范围是0-127,主要用于表示英语字母;而Unicode的编码范围广阔得多,可以表示几乎所有的语言字符。
2.存储空间不同
ASCII编码通常使用1个字节来存储一个字符,而Unicode编码可能使用2个或更多的字节来存储一个字符。
3.兼容性不同
ASCII编码是Unicode编码的一部分,也就是说,所有的ASCII字符在Unicode编码中都有对应的编码。这也意味着ASCII编码的文本可以直接转换为Unicode编码,而不会丢失任何信息。
