How to join a slice of strings into a single string?

package main

import (
"fmt"
"strings"
)

func main() {
reg := [...]string {"a","b","c"}
fmt.Println(strings.Join(reg,","))
}

gives me an error of:

prog.go:10: cannot use reg (type [3]string) as type []string in argument to strings.Join

Is there a more direct/better way than looping and adding to a var?

3 Answers
3

Leave a Comment