Essential Go Strings  Edit on GitHub      File Issue

Split and join strings

You can split a string into a []string slice and join it back into a string.

s := "this is a string"
a := strings.Split(s, " ")
fmt.Printf("a: %#v\n", a)

s2 := strings.Join(a, ",")
fmt.Printf("s2: %#v\n", s2)
a: []string{"this", "is", "a", "string"}
s2: "this,is,a,string"

Joining a slice of strings is faster that using +.

  ↑ ↓ to navigate     ↵ to select     Esc to close