]> Cypherpunks repositories - gostls13.git/commitdiff
strings: add a example for TrimFunc
authorFrancisco Rojas <francisco.rojas.gallegos@gmail.com>
Sat, 15 Jul 2017 20:51:58 +0000 (14:51 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 15 Jul 2017 21:14:22 +0000 (21:14 +0000)
Change-Id: I9c0c601ec5957475e949dcc4a8c2116724d01215
Reviewed-on: https://go-review.googlesource.com/48961
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

src/strings/example_test.go

index 473b8c38339ae527420bc3ae694304f1ece2903c..e9621522ef223de9e05cc229295768f244c4d586 100644 (file)
@@ -234,6 +234,14 @@ func ExampleTrim() {
        // Output: ["Achtung! Achtung"]
 }
 
+func ExampleTrimFunc() {
+       f := func(c rune) bool {
+               return !unicode.IsLetter(c) && !unicode.IsNumber(c)
+       }
+       fmt.Printf("[%q]", strings.TrimFunc("  Achtung1! Achtung2,...", f))
+       // Output: ["Achtung1! Achtung2"]
+}
+
 func ExampleMap() {
        rot13 := func(r rune) rune {
                switch {