doxrxwn2252
doxrxwn2252
2017-08-21 16:27

附加到切片中的for循环中具有意外结果

  • slice

It could be a silly question but when I try to append a []byte slice to a [][]byte slice I get weird results.

Here is my code:

func Normalizer(s string) (ss [][]byte) {

    ss = make([][]byte, 0)
    // norm
    var ia norm.Iter

    ia.InitString(norm.NFC, s)

    for !ia.Done() {

        next := ia.Next()

        fmt.Println(next)
        // [226 128 139]
        // [227 128 129]
        // [39]
        // [226 128 153]
        // [46]
        // [44]
        // [63]
        // [33]
        // [92]
        // [10]
        // [226 128 153]
        // ...
        ss = append(ss, next)

    }
    ia.Done()


    fmt.Println(ss)
    return
}

I'm expecting somethin like this:

// [[226 128 139] [227 128 129] [39] [226 128 153] [46] [44] [63] [33] [92] [10] [226 128 153]...] 

but instead i get this:

// [[226 129 128] [226 129 128] [226] [226 129 128] [226] [226] [226] [226] [226] [226] [226 129 128]...]

and I have no idea why. Help and explanation would be appreciated.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐