diff options
| author | Robin Eklind <r.eklind.87@gmail.com> | 2013-12-16 10:44:23 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2013-12-16 10:44:23 -0800 |
| commit | ab9b2ae38cced9938bb5d8dfdc671fcd2be9b204 (patch) | |
| tree | 3e7e77ed63c682ffd0f1542e1a3d575e6bee6ab9 /src/pkg/strings | |
| parent | 7b53e32e0bfda3bf63c608a83a46a75c7d2e969f (diff) | |
| download | go-ab9b2ae38cced9938bb5d8dfdc671fcd2be9b204.tar.xz | |
strings: Add IndexFunc example
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/42370043
Diffstat (limited to 'src/pkg/strings')
| -rw-r--r-- | src/pkg/strings/example_test.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/pkg/strings/example_test.go b/src/pkg/strings/example_test.go index 7350131b85..62a9af74d0 100644 --- a/src/pkg/strings/example_test.go +++ b/src/pkg/strings/example_test.go @@ -68,6 +68,17 @@ func ExampleIndex() { // -1 } +func ExampleIndexFunc() { + f := func(c rune) bool { + return unicode.Is(unicode.Han, c) + } + fmt.Println(strings.IndexFunc("Hello, 世界", f)) + fmt.Println(strings.IndexFunc("Hello, world", f)) + // Output: + // 7 + // -1 +} + func ExampleIndexRune() { fmt.Println(strings.IndexRune("chicken", 'k')) fmt.Println(strings.IndexRune("chicken", 'd')) |
