Last Updated: February 25, 2016
·
8.889K
· greynaert

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())
 }

try it!

sources