golang 字符串拼接的 5 种方式

package main

import (
    "bytes"
    "fmt"
    "strings"
)

func main() {
    s1 := fmt.Sprintf("%s - %s", "a", "b")
    fmt.Println("s1:", s1)

    var str []string = []string{"aa", "bb"}
    s2 := strings.Join(str, ",")
    fmt.Println("s2:", s2)

    var bt bytes.Buffer
    bt.WriteString("aaa")
    bt.WriteString("bbb")
    s3 := bt.String()
    fmt.Println("s3:", s3)

    var build strings.Builder
    build.WriteString("aaaa")
    build.WriteString("bbbb")
    s4 := build.String()
    fmt.Println("s4:", s4)

    s5 := "aaaaa" + "bbbbb"
    fmt.Println("s5:", s5)
}
打赏作者

您将是第一位评论人!

提醒
avatar