Last active
October 14, 2020 06:07
-
-
Save gimsesu/d1d3fc3b8ac434bf49579e4e1907ba36 to your computer and use it in GitHub Desktop.
Snippet: String-concatenation (Golang)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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