From 37b056948d058679efa4e87fb6c9b2a2ddfa31a3 Mon Sep 17 00:00:00 2001 From: Caleb Spare Date: Tue, 31 Oct 2017 16:51:21 -0700 Subject: strings: add Builder This is like a write-only subset of bytes.Buffer with an allocation-free String method. Fixes #18990. Change-Id: Icdf7240f4309a52924dc3af04a39ecd737a210f4 Reviewed-on: https://go-review.googlesource.com/74931 Run-TryBot: Caleb Spare TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/strings/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/strings/example_test.go') diff --git a/src/strings/example_test.go b/src/strings/example_test.go index f7a78b4385..607e4a0a70 100644 --- a/src/strings/example_test.go +++ b/src/strings/example_test.go @@ -351,3 +351,14 @@ func ExampleTrimRightFunc() { })) // Output: ¡¡¡Hello, Gophers } + +func ExampleBuilder() { + var b strings.Builder + for i := 3; i >= 1; i-- { + fmt.Fprintf(&b, "%d...", i) + } + b.WriteString("ignition") + fmt.Println(b.String()) + + // Output: 3...2...1...ignition +} -- cgit v1.3