bytes, strings: add TrimPrefix and TrimSuffix
Everybody either gets confused and thinks this is
TrimLeft/TrimRight or does this by hand which gets
repetitive looking.
R=rsc, kevlar
CC=golang-dev
https://golang.org/cl/7239044
diff --git a/src/pkg/strings/example_test.go b/src/pkg/strings/example_test.go
index 733caf5..36e0a42 100644
--- a/src/pkg/strings/example_test.go
+++ b/src/pkg/strings/example_test.go
@@ -179,3 +179,19 @@
fmt.Println(strings.ToLower("Gopher"))
// Output: gopher
}
+
+func ExampleTrimSuffix() {
+ var s = "Hello, goodbye, etc!"
+ s = strings.TrimSuffix(s, "goodbye, etc!")
+ s = strings.TrimSuffix(s, "planet")
+ fmt.Print(s, "world!")
+ // Output: Hello, world!
+}
+
+func ExampleTrimPrefix() {
+ var s = "Goodbye,, world!"
+ s = strings.TrimPrefix(s, "Goodbye,")
+ s = strings.TrimPrefix(s, "Howdy,")
+ fmt.Print("Hello" + s)
+ // Output: Hello, world!
+}