Concat strings in GOLANG
String is a primitive type it can't be changed, you can concate by using the +=
operator but it creates a new string everytime you use it.
The best way to do, Is to use a bytes buffer and then get the string.
package main
import "fmt"
import "bytes"
func main() {
list := []string{"foo", "bar"}
var str bytes.Buffer
for _, l := range list {
str.WriteString(l)
}
fmt.Println(str.String())
}
Written by Guillaume
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Golang
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#