Golang converting from rune to string

前端 未结 2 708
别那么骄傲
别那么骄傲 2021-02-02 06:49

I have the following code, it is supposed to cast a rune into a string and print it. However, I am getting undefined characters when it is printed. I a

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 07:31

    I know I'm a bit late to the party but here's a []rune to string function:

    func runesToString(runes []rune) (outString string) {
        // don't need index so _
        for _, v := range runes {
            outString += string(v)
        }
        return
    }
    

    yes, there is a named return but I think it's ok in this case as it reduces the number of lines and the function is only short

提交回复
热议问题