Skip to content

Instantly share code, notes, and snippets.

@gimsesu
Last active October 14, 2020 06:07
Show Gist options
  • Save gimsesu/d1d3fc3b8ac434bf49579e4e1907ba36 to your computer and use it in GitHub Desktop.
Save gimsesu/d1d3fc3b8ac434bf49579e4e1907ba36 to your computer and use it in GitHub Desktop.
Snippet: String-concatenation (Golang)
package main
import (
"fmt"
"bytes"
)
func bufString(s ...string) string {
var buf bytes.Buffer
if len(s) > 0 {
for _, v := range s {
buf.WriteString(v)
}
}
return buf.String()
}
func main() {
a := "Hello "
b := "World"
result := bufString(a, b)
fmt.Println(result)
// "Hello Wolrd"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment