mirror of https://github.com/golang/go.git
strings: Add FieldsFunc example.
R=golang-dev, dave CC=golang-dev https://golang.org/cl/42360043
This commit is contained in:
parent
c184940d3f
commit
a6ebc88bac
|
|
@ -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"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue