]> Cypherpunks repositories - gostls13.git/commitdiff
strings: Add FieldsFunc example.
authorRobin Eklind <r.eklind.87@gmail.com>
Mon, 16 Dec 2013 17:43:03 +0000 (09:43 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 16 Dec 2013 17:43:03 +0000 (09:43 -0800)
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/42360043

src/pkg/strings/example_test.go

index 36e0a42fb031099829d9f2f2a90aa7c0a3d35f5c..ccfc4172c39c712295492dfc079eccd4562f27cc 100644 (file)
@@ -7,6 +7,7 @@ package strings_test
 import (
        "fmt"
        "strings"
+       "unicode"
 )
 
 func ExampleFields() {
@@ -14,6 +15,14 @@ func ExampleFields() {
        // Output: Fields are: ["foo" "bar" "baz"]
 }
 
+func ExampleFieldsFunc() {
+       f := func(c rune) bool {
+               return !unicode.IsLetter(c) && !unicode.IsNumber(c)
+       }
+       fmt.Printf("Fields are: %q", strings.FieldsFunc("  foo1;bar2,baz3...", f))
+       // Output: Fields are: ["foo1" "bar2" "baz3"]
+}
+
 func ExampleContains() {
        fmt.Println(strings.Contains("seafood", "foo"))
        fmt.Println(strings.Contains("seafood", "bar"))