Split and join strings
suggest changeYou 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 +
.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents