Golang 中 \u001b[?2004h 乱码解决方法
Golang 中 \u001b[?2004h 乱码问题解决
在 Go 语言中,'\u001b' 表示一个特殊的控制字符,'\u001b[?2004h' 则用于开启或关闭终端的剪贴板支持。
如果你想将其显示为普通文本,可以使用 fmt.Printf 函数的 %q 格式化动词。
示例代码:
package main
import 'fmt'
func main() {
str := '\u001b[?2004hroot@7b54c485eea8:/# '
fmt.Printf('%q\n', str)
}
运行结果:
'\033[?2004hroot@7b54c485eea8:/# '
其中,'\033' 是 '\u001b' 的八进制表示。
原文地址: https://www.cveoy.top/t/topic/fxGO 著作权归作者所有。请勿转载和采集!