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 :
Advertisement
Something interesting
Tutorials
+32.2k Golang : Convert []string to []byte examples
+6.6k Golang : Embedded or data bundling example
+13.8k Golang : unknown escape sequence error
+10.1k Golang : How to tokenize source code with text/scanner package?
+30.4k Golang : How to redirect to new page with net/http?
+12.7k Golang : Sort and reverse sort a slice of bytes
+11.6k Golang : Display a text file line by line with line number example
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+19.2k Golang : Check whether a network interface is up on your machine
+6.3k Javascript : Generate random key with specific length
+8.1k Golang : How To Use Panic and Recover
+12k Golang : Clean formatting/indenting or pretty print JSON result