]> Cypherpunks repositories - gostls13.git/commitdiff
strings: add examples for Index functions
authormolivier <olivier.matthieu@gmail.com>
Tue, 8 Aug 2017 15:39:52 +0000 (17:39 +0200)
committerIan Lance Taylor <iant@golang.org>
Wed, 9 Aug 2017 04:43:33 +0000 (04:43 +0000)
Change-Id: Ia0f0c8ab4f2f9e96faad6d88775ae19ca7fae53c
Reviewed-on: https://go-review.googlesource.com/53790
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Avelino <t@avelino.xxx>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/strings/example_test.go

index f35452369d44707e584cd64247745aab4a1eb4b2..ba67458d1ff734bbac7358c30bfaa0e9dad15441 100644 (file)
@@ -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, ", "))