Answer the question
In order to leave comments, you need to log in
How to pass an array []string to a function that accepts ... string?
Actually the question is in the title.
If I pass it directly, then when the program is executed, something like this comes out:panic: sql: expected 4 arguments, got 1
Answer the question
In order to leave comments, you need to log in
If I understand correctly, something like this:
func add(args ...string) (total string) {
for _, v := range args {
total += v
}
return
}
func main() {
fmt.Println(add("1", "2", "3")) // 123
xs := []string{"1", "2", "3"}
fmt.Println(add(xs...)) // 123
}
...string
Means that you want to pass an indefinite number of parameters with type string
for example concatenation
func Concat(strings ...string) bytes.Buffer {
buffer := bytes.Buffer{}
for _, str := range strings {
buffer.WriteString(str)
}
return buffer
}
Concat("Строка 1", "Строка 2", "Строка 3", "Строка 4", "Строка 5")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question