问题描述
我在上阅读了这篇文章
这是真的吗? (它似乎是一个从知道Go的人的博客)。我在我的机器上测试,è是1符文和2字节。而且似乎有所不同。
你遇到过这样的字符吗?
可以:
s:=é
> nofollow> Go Playground ):
fmt.Println(s,[] rune(s))
é[101 769 769 769]
一个字符,4个符文。它可能是任意长...
示例取自(修饰符可以重复和堆叠):
另请参阅:。
编辑:这不是杀死了符文的概念吗?
回答:这不是符文的概念。
rune
不是字符。 rune是标识Unicode代码点的整数值。字符 可以是一个Unicode代码点,在这种情况下,1个字符为1rune
。大多数一般使用rune
s适合这种情况,因此在实践中这几乎不会造成任何头痛。这是的概念。I read this on this blog
Is it true ? (it seems like a blog from someone who knows Go). I tested on my machine and "è" is 1 rune and 2 bytes. And the Go doc seems to say otherwise.
Have you encountered such characters ? (utf-8) Can a character span multiple runes in Go ?
解决方案Yes it can:
s := "é́́" fmt.Println(s, []rune(s))
Output (try it on the ):
é́́ [101 769 769 769]
One character, 4 runes. It may be arbitrary long...
Example taken from The Go Blog: Text Normalization in Go.
A character can be followed by any number of modifiers (modifiers can be repeated and stacked):
Also see: Combining character.
Edit: "Doesn't this kill the 'concept of runes'?"
Answer: It's not a concept of runes. A
rune
is not a character. A rune is an integer value identifying a Unicode code point. A character may be one Unicode code point in which case 1 character is 1rune
. Most of the general use ofrune
s fits into this case, so in practice this hardly gives any headaches. It's a concept of the Unicode standard.这篇关于一个人物可以跨越多个符文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!