golang convert "type []string" to string

user3888307 picture user3888307 · Jan 20, 2017 · Viewed 74.3k times · Source

I'm sure this is a simple question, but I keep bumping into this. I see others are as well.

I see some people create a for loop and run through the slice as to create a string, is there an easier way to convert a []string to a string?

Will sprintf do it?

Answer

Tom Regner picture Tom Regner · Jan 20, 2017

You can use strings.Join(arr []string, seperator string) string, as in pretty much any other language I know

https://golang.org/pkg/strings/#Join