shad-go/lectures/10-io/stringsbuilder/main.go
2022-04-21 01:22:13 +03:00

18 lines
298 B
Go

package main
import (
"fmt"
"strings"
)
func concat(x, y string) string {
var builder strings.Builder
builder.Grow(len(x) + len(y)) // only this line allocates
builder.WriteString(x)
builder.WriteString(y)
return builder.String()
}
func main() {
fmt.Println(concat("hello ", "world"))
}