The title of your question is:
How to join a slice of strings into a single string?
but in fact, reg
is not a slice, but a length-three array. [...]string
is just syntactic sugar for (in this case) [3]string
.
To get an actual slice, you should write:
reg := []string {"a","b","c"}
(Try it out: https://play.golang.org/p/vqU5VtDilJ.)
Incidentally, if you ever really do need to join an array of strings into a single string, you can get a slice from the array by adding [:]
, like so:
fmt.Println(strings.Join(reg[:], ","))
(Try it out: https://play.golang.org/p/zy8KyC8OTuJ.)