Split and join strings

suggest change

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

main.go

	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)

Output:

a: []string{"this", "is", "a", "string"}
s2: "this,is,a,string"

Joining a slice of strings is faster that using +.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents