dongmei425373 2017-04-15 11:33
浏览 13
已采纳

Golang和UTF-8中的符文[关闭]

  1. What does "rune" mean?

  2. https://golang.org/pkg/unicode/utf8/#example_Valid Why is the answer is true in the first line?

  3. The function Valid accepts only an array?

  • 写回答

1条回答 默认 最新

  • donglu5235 2017-04-15 12:05
    关注
    1. rune is an alias for the type int32. It is intended to make programs clear about the cases when an integer value represents a code point.
    2. Because the sequence of bytes 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0xe4, 0xb8, 0x96, 0xe7, 0x95, 0x8c (which is a representation of the utf-8 string Hello, 世界) is a valid UTF-8 sequence.
    3. While utf8.Valid accepts only array of bytes (there is no overloading in Go, so the "only" part is actually irrelevant), there are a few similar functions to check for validness: utf8.ValidRune and utf8.ValidString

    I recommend reading an awesome article on the Go blog: Strings, bytes, runes and characters in Go, I believe after reading it and experimenting a bit you'll get answers to most of your utf8-related questions about Go.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部