add new concat

main
hau 2020-09-06 16:35:58 +07:00
parent 35f86b8c87
commit ca3c998ccc
1 changed files with 20 additions and 0 deletions

View File

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