008-Go 关于字符串拼接
如果是少量小文本拼接,用 “+”
如果是大量小文本拼接,用 strings.Join
如果是大量大文本拼接,用 bytes.Buffer
package main import( "fmt" "bytes" "strings" ) func main(){ fmt.Println("Hello,"+"Go1!") var s string s = strings.Join([]string{s,""}, "Hello,") s = strings.Join([]string{s,""}, "Go2!") fmt.Println(s) var buf bytes.Buffer buf.WriteString("Hello") buf.WriteString(",Go3!") fmt.Println(buf.String()) }