*简述 Golang String类型使用细节


1、字符串一旦赋值了,就不能修改了,在Go中字符串是不可变的
2、字符串用双引号 “”会识别转译字符.eg:反引号
3、字符串要想原生输出(输出一段代码),包括换行符和其他特殊符号,则需要 反引号 ` ,可以实现防止攻击


字符串的拼接方式:

var str = "hello" + "word"
str += "haha"

fmt.Println(str)

运行结果:
hello word haha

当拼接一个很长的字符串时候, + 号 一定要放到每行的最后
demo:

var str = "hello" + "word" + "hello" + "word" + "hello" + "word" + 
"hello" + "word" + "hello" + "word" + "hello" +
"hello" + "word" "hello" + "word" 
fmt.Println(str)

猜你喜欢

转载自blog.csdn.net/weixin_44355591/article/details/106178512