Skip to content

Go Error: Argument Problem for strings.Join

You are facing an error that says you are not using the correct type, a slice of string!

cannot use reg (variable of type [3]string) as type []string in argument to strings.Join

Yes, you are sending an array (which is not a slice) as an argument into the join function.

Take a look at this example:

package main

import (

func main() {
	list := [...]string{"a", "b", "c"} // this creates an array

	fmt.Println(strings.Join(list, ",")) // Bad, remove this line

	fmt.Println(strings.Join(list[:], ",")) // Good

Leave a Reply

Your email address will not be published. Required fields are marked *