Answer the question
In order to leave comments, you need to log in
How to properly concatenate strings in golang?
I saw a similar question in ang stack, but an attempt to implement it resulted in an error:
miltiple-value buffer.WriteString() in single-value context
The code was like this
package main
import (
"fmt"
"bytes"
)
func main() {
var x []string
letter := [3]string{"a","б","в"}
for i := 0; i < len(letter); i++ {
var buffer bytes.Buffer
x = append(x, buffer.WriteString(letter[i]))
}
fmt.Println(x)
}
package main
import "strings"
import "fmt"
func main() {
var x []string
letter := [3]string{"a","б","в"}
for i := 0; i < len(letter); i++ {
var z string = ""
x = append(x, z.Join([]string{"a", "b"}, "-"))
}
fmt.Println(x)
}
Answer the question
In order to leave comments, you need to log in
You do not call strings.Join()
, the correct option is:
func main() {
var x []string
letter := [3]string{"a","б","в"}
for i := 0; i < len(letter); i++ {
x = append(x, strings.Join([]string{"a", "b"}, "-"))
}
fmt.Println(x)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question