我正在编写一个用 Go 语言读取文件的代码。为了做到这一点,我使用 fmt.Println()
将内容输出到中间文件中。
如何打印出 "
符号?
这非常简单,就像C语言一样。
fmt.Println("\"")
不要说 Go 没有选择。以下所有选项都会打印一个引号 "
:
fmt.Println("\"")
fmt.Println("\x22")
fmt.Println("\u0022")
fmt.Println("\042")
fmt.Println(`"`)
fmt.Println(string('"'))
fmt.Println(string([]byte{'"'}))
fmt.Printf("%c\n", '"')
fmt.Printf("%s\n", []byte{'"'})
// Seriously, this one is just for demonstration not production :)
fmt.Println(xml.Header[14:15])
fmt.Println(strconv.Quote("")[:1])
在Go Playground上尝试它们。
fmt.Println(\
"`)`。 - Elias Van Ootegem