2017-01-31 53 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