One - One Code All

Blog Content

golang字符串拼接几种方式

Go   2018-01-17 21:13:38

golang字符串拼接几种方式


实例:

package main

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

func main() {
    // 字符串拼接1
    s1 := fmt.Sprintf("%s:%d", "127.0.0.1", 8080)
    fmt.Println(s1)

    // 字符串拼接2
    s2 := strings.Join([]string{"hello", "world"}, "")
    fmt.Println(s2)

    // 字符串拼接3
    s3 := bytes.Buffer{}
    s3.WriteString("hello")
    s3.WriteString("world")
    fmt.Println(s3.String())

    // 字符串拼接4
    s4 := "hello" + "world"
    fmt.Println(s4)
}



上一篇:golang判断map中key是否存在的方法
下一篇:Mac-safari安装浏览器扩展

The minute you think of giving up, think of the reason why you held on so long.