diff options
| author | Robin Eklind <r.eklind.87@gmail.com> | 2013-12-16 09:43:03 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2013-12-16 09:43:03 -0800 |
| commit | a6ebc88bace75ea1eb978ed2d1267e4ac3e9a99a (patch) | |
| tree | ce71464e42469be5ba913d406523f5b61154c8c8 /src/pkg/strings | |
| parent | c184940d3fb1090eba5c3747a21cfa50771e12fd (diff) | |
| download | go-a6ebc88bace75ea1eb978ed2d1267e4ac3e9a99a.tar.xz | |
strings: Add FieldsFunc example.
R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/42360043
Diffstat (limited to 'src/pkg/strings')
| -rw-r--r-- | src/pkg/strings/example_test.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/pkg/strings/example_test.go b/src/pkg/strings/example_test.go index 36e0a42fb0..ccfc4172c3 100644 --- a/src/pkg/strings/example_test.go +++ b/src/pkg/strings/example_test.go @@ -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")) |
