diff --git a/Development/Go/strings.md b/Development/Go/strings.md index 57af105..23b134c 100644 --- a/Development/Go/strings.md +++ b/Development/Go/strings.md @@ -7,3 +7,23 @@ template := "My city is {city} and my country is {country}" r := strings.NewReplacer("{city}", "Sai Gon", "{country}", "Viet Nam") fmt.Println(r.Replace(template)) ``` + +Use `Builder` to **efficently** concat string: + +```go +func oldConcat(strs ...string) string { + var result string + for _, str := range strs { + result += str + } + return result +} + +func newConcat(strs ...string) string { + var sb strings.Builder + for _, str := range strs { + sb.WriteString(str) + } + return sb.String() +} +```