From 8fb9cee3f1a6333ad50d7ca382e9a0bdafc1b5b6 Mon Sep 17 00:00:00 2001 From: molivier Date: Tue, 8 Aug 2017 17:39:52 +0200 Subject: [PATCH] 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 --- src/strings/example_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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, ", ")) -- 2.48.1