首页  

GO字符串拼接     所属分类 go 浏览量 74
+拼接字符串
字符串不可变 ,用 + 连接会产生一个新的字符串

s1 := "hello"
s2 := "world"
s3 := s1 + s2
fmt.Println(s3)

sprintf函数
s1 := "hello"
s2 := "world"
s3 := fmt.Sprintf("%s%s", s1, s2)
fmt.Println(s3)

strings.Join
s1 := "hello"
s2 := "world"
var str []string = []string{s1, s2}
s3 := strings.Join(str, "")
fmt.Println(s3)

buffer.WriteString
s1 := "hello"
s2 := "world"
var buf bytes.Buffer
buf.WriteString(s1)
buf.WriteString(s2)
s3 := buf.String()
fmt.Println(s3)


buffer.Builder

s1 := "hello"
s2 := "world"
var sb strings.Builder
sb.WriteString(s1)
sb.WriteString(s2)
s3 := sb.String()
fmt.Println(s3)



https://gitee.com/dyyx/hellocode/blob/master/web/tech/go/demo/strdemo.go

上一篇     下一篇
保险合同要点

开公司要知道的财税制度

GO panic recover

go socket 编程 echo server

java HTTP Server NanoHttpd

java nio echo server