dongyou5068 2018-06-26 05:55
浏览 57
已采纳

Go如何处理大于单个字节的字符?

In Go a byte is the same as an uint8. Which means a byte can store a value between 0 and 255.

A string can also be written as a slice of bytes. I've read that there are almost no differences between a string and a slice of bytes (except the mutability).

So how is it possible in Go to write something like "世界" when this is clearly not in the first 255 characters in the UTF-8 encoding table? How does Go handle characters that are not within the first 255 rows in the UTF8 encoding table?

  • 写回答

1条回答 默认 最新

  • douzhan1963 2018-06-26 06:37
    关注

    Go uses UTF-8 encoding for source files, string literals, []rune to string conversions, string to []rune conversions, integer to string conversions and on range over string.

    UTF-8 uses one to four bytes to encode a character.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM