What does "rune" mean?
https://golang.org/pkg/unicode/utf8/#example_Valid Why is the answer is true in the first line?
The function Valid accepts only an array?
What does "rune" mean?
https://golang.org/pkg/unicode/utf8/#example_Valid Why is the answer is true in the first line?
The function Valid accepts only an array?
收起
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.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.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.
报告相同问题?