Golang bytes.LastIndex() function example
package bytes
LastIndex returns the index of the last instance of the search key in the given input and returns -1 if there is no match.
Golang bytes.LastIndex() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
str := []byte("abcdefg...xyz")
fmt.Println(bytes.LastIndex(str, []byte("x")))
str2 := []byte("abcxyz")
fmt.Println(bytes.LastIndex(str2, []byte("x")))
}
Output :
10
3
Reference :
Advertisement
Something interesting
Tutorials
+19.7k Golang : Archive directory with tar and gzip
+9.4k Facebook : Getting the friends list with PHP return JSON format
+11.5k Golang : Change date format to yyyy-mm-dd
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+16.4k Golang : Send email and SMTP configuration example
+17.5k Golang : Find smallest number in array
+13.2k Golang : Convert(cast) int to int64
+15k Golang : package is not in GOROOT during compilation
+8.2k Golang : Routes multiplexer routing example with regular expression control
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+6.1k Golang : Get missing location after unmarshal binary and gob decode time.
+18.9k Golang : Read input from console line