简体   繁体   中英

Printing " (double quote) in GoLang

I am writing a Go code which reads from a file. To do so I use fmt.Println() to print into that intermediate file.

How can I print " ?

这很容易,就像C.

fmt.Println("\"")

Old style string literals and their escapes can often be avoided. The typical Go solution is to use a raw string literal here:

 fmt.Println(`"`)

Don't say Go doesn't leave you options. The following all print a quotation mark " :

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])

Try them on the Go Playground .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM