2017-01-31 55 views
11

我写一个围棋代码从文件读取(双引号)。为此我使用fmt.Println()打印成中间文件。打印“在GoLang

我如何打印"

回答

16

这是很容易的,就像C.

fmt.Println("\"") 
+6

更容易甚至'FMT。 Println(\'“\')' –

11

旧风格的字符串和经常可以避开他们逃脱典型转到解决方案是在这里使用一个raw string literal

fmt.Println(`"`) 
+1

我认为这是更可读的解决方案 – CheeseFerret

11

不要说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