How to convert a rune to unicode-style-string like `\u554a` in Golang?

后端 未结 8 1751
心在旅途
心在旅途 2021-02-05 07:47

If you run fmt.Println(\"\\u554a\"), it shows \'啊\'.

But how to get unicode-style-string \\u554a from a rune \'啊\' ?

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 08:17

    This would do the job..

    package main
    
    import (
        "fmt"
    )
    
    func main() {
        str := fmt.Sprintf("%s", []byte{0x80})
        fmt.Println(str)
    }
    

提交回复
热议问题