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 "
?
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 "
?
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.
© 2022 - 2024 — McMap. All rights reserved.
fmt.Println(`"`)
– Hackery