这是来自Go blog的练习。[Exercise: Put an invalid UTF-8 byte sequence into the string. (How?) What happens to the iterations of the loop?]
我所做的是

    const nihongo = "\xbd日本語\xbd"
    for index, runeValue := range nihongo {
        fmt.Printf("%x, %d\n", runeValue, index)
    }

输出是
fffd, 0
65e5, 1
672c, 4
8a9e, 7
fffd, 10

我的问题是。 utf-8编码的字节bd如何格式化为单位代码点u+fffd

最佳答案

此行为由Spec: For statements:指定

09-25 19:21