Golang bytes.LastIndexAny() function example

package bytes

LastIndexAny interprets given input as a sequence of UTF-8-encoded Unicode code points. It returns the byte index of the last occurrence of the search key in Unicode code points in the given input. It returns -1 if there is no match.

Golang bytes.LastIndexAny() function usage example

 package main

 import (
 "fmt"
 "bytes"
 )

 func main() {

  str := []byte("abcdefg...xyz")

  fmt.Println(bytes.LastIndexAny(str, "xyz"))

  fmt.Println(bytes.LastIndexAny(str, "zyx"))

  fmt.Println(bytes.LastIndexAny(str, "P"))

  fmt.Println(bytes.LastIndexAny(str, ""))

 }

Output :

12

12

-1

-1

Reference :

http://golang.org/pkg/bytes/#LastIndexAny

Advertisement