From: molivier Date: Tue, 8 Aug 2017 15:39:52 +0000 (+0200) Subject: strings: add examples for Index functions X-Git-Tag: go1.10beta1~1690 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8fb9cee3f1a6333ad50d7ca382e9a0bdafc1b5b6;p=gostls13.git strings: add examples for Index functions Change-Id: Ia0f0c8ab4f2f9e96faad6d88775ae19ca7fae53c Reviewed-on: https://go-review.googlesource.com/53790 Reviewed-by: Ian Lance Taylor Reviewed-by: Avelino Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/strings/example_test.go b/src/strings/example_test.go index f35452369d..ba67458d1f 100644 --- a/src/strings/example_test.go +++ b/src/strings/example_test.go @@ -166,6 +166,26 @@ func ExampleLastIndexAny() { // -1 } +func ExampleLastIndexByte() { + fmt.Println(strings.LastIndexByte("Hello, world", 'l')) + fmt.Println(strings.LastIndexByte("Hello, world", 'o')) + fmt.Println(strings.LastIndexByte("Hello, world", 'x')) + // Output: + // 10 + // 8 + // -1 +} + +func ExampleLastIndexFunc() { + fmt.Println(strings.LastIndexFunc("go 123", unicode.IsNumber)) + fmt.Println(strings.LastIndexFunc("123 go", unicode.IsNumber)) + fmt.Println(strings.LastIndexFunc("go", unicode.IsNumber)) + // Output: + // 5 + // 2 + // -1 +} + func ExampleJoin() { s := []string{"foo", "bar", "baz"} fmt.Println(strings.Join(s, ", "))