Go语言中可以使用反引号(``)包含多行字符串,它们可以包含任意字符,甚至包括换行符。例如:
str := ` pidancode.com 皮蛋编程 ` fmt.Println(str)
输出结果为:
pidancode.com 皮蛋编程
在多行字符串中想要插入一个换行符,可以用\n来表示。
),可以使用反斜杠(\
str := `\`pidancode.com\`` fmt.Println(str)
\pidancode.com\
如果需要在字符串中插入反斜杠本身,需要使用两个反斜杠(\),例如:
str := `pidancode.com\\` fmt.Println(str)
pidancode.com\
需要注意的是,反斜杠是 Go 语言中的转义符,因此如果在字符串中需要插入其他的转义符,需要一并转义,例如:
str := "Hello\tWorld\n" fmt.Println(str)
输出结果为:
Hello World
\t\n