mirror of
https://github.com/golang/go
synced 2024-10-14 03:43:28 +00:00
strings: Add IndexFunc example
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/42370043
This commit is contained in:
parent
7b53e32e0b
commit
ab9b2ae38c
|
@ -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'))
|
||||
|
|
Loading…
Reference in a new issue