You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a string value, the "range" clause iterates over the Unicode code points in the string starting at byte index 0. On successive iterations, the index value will be the index of the first byte of successive UTF-8-encoded code points in the string, and the second value, of type rune, will be the value of the corresponding code point.
书中涉及之处有:
2.2.2节-3
第78页
range作用于string时……元素值是该字符对应的Unicode编码的首个字节的值
第79页
range的第二个返回值的类型为rune类型,它仅代表Unicode编码的1个字节
2.2.3节-3
第83页
返回的元素值为rune类型的单个字节值……该字节值仅代表Unicode编码的首个字节
The text was updated successfully, but these errors were encountered:
在用for...range迭代string时,range返回的第二个值是rune类型,其内容为对应字符的(完整的)Unicode码点。不过书中一直说是Unicode编码的首字节,而不是全部。
Go语言规范中的说法也是Unicode码点:https://golang.org/ref/spec#For_range
书中涉及之处有:
2.2.2节-3
第78页
第79页
2.2.3节-3
第83页
The text was updated successfully, but these errors were encountered: