Go语言的两种字符串双引号和反引号
- 编辑整理:
- 匿名
- 热度:
- 7567
字符串表示两种方式:1)双引号2)``(反引号,键盘左上角数字1左边那个~键)
go语言字符串表示两种方式: 1)双引号 2)`` (反引号,键盘左上角数字1左边那个~键)2711
package main
0192b64e
import “fmt”0c6a
func main() {f93
var str = “hello world\n\n” f93
var str2 = `hello \n \n \n`2711
this is a test stringf93
This is a test string too·`a0efda5
fmt.Println(“str=“, str)a2a4995
fmt.Println(“str2=“, str2)a2a4995
} www.9lyp.com
输出str:hello world0c6a
后面没有\n,变成了换行a0efda5
f93
输出str2:hello \n \n \n
0192b64e
原样输出,在需要保留格式时使用。包括\n也原样输出。2711
package main0c6a
import "fmt"
0192b64e
func main() {a0efda5
var str = "hello world\n\n"f93
var str2 = `f93
菱叶萦波荷飐风,荷花深处小船通。a2a4995
逢郎欲语低头笑,碧玉搔头落水中。\n \n \n`f93
fmt.Println("str=", str)2711
fmt.Println("str2=", str2)a2a4995
}
0192b64e
输出:
f93
str= hello worldwww.9lyp.com
str2=
0192b64e
菱叶萦波荷飐风,荷花深处小船通。a2a4995
逢郎欲语低头笑,碧玉搔头落水中。\n \n \na0efda5
0192b64e
a2a4995