本文介绍了一个人物可以跨越多个符文吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在上阅读了这篇文章

这是真的吗? (它似乎是一个从知道Go的人的博客)。我在我的机器上测试,è是1符文和2字节。而且似乎有所不同。



你遇到过这样的字符吗?

解决方案

可以:

  s:=é
fmt.Println(s,[] rune(s))
> nofollow> Go Playground ):

 é[101 769 769 769] 

一个字符,4个符文。它可能是任意长...



示例取自(修饰符可以重复和堆叠):

另请参阅:。



编辑:这不是杀死了符文的概念吗?



回答:这不是符文的概念。 rune 不是字符。 rune是标识Unicode代码点的整数值。字符 可以是一个Unicode代码点,在这种情况下,1个字符为1 rune 。大多数一般使用 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 1 rune. Most of the general use of runes fits into this case, so in practice this hardly gives any headaches. It's a concept of the Unicode standard.

这篇关于一个人物可以跨越多个符文吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 18:08