如何将 rune 转换为 unicode-style-string,如 Golang 中的 `\u554a`?

2023-12-31

如果你跑fmt.Println("\u554a"),显示‘啊’。

但是如何获取 unicode-style-string\u554a来自符文“啊”?


package main

import "fmt"
import "strconv"

func main() {
    quoted := strconv.QuoteRuneToASCII('啊') // quoted = "'\u554a'"
    unquoted := quoted[1:len(quoted)-1]      // unquoted = "\u554a"
    fmt.Println(unquoted)
}

这输出:



\u554a
  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 rune 转换为 unicode-style-string,如 Golang 中的 `\u554a`? 的相关文章

随机推荐