Golang bytes.Index() function example
package bytes
Index returns the index of the first instance of the search key in the search input. The index function returns -1 if the search key is not present in search input.
Golang bytes.Index() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
search_input := []byte("abcd和efghi")
fmt.Println(bytes.Index(search_input, []byte("和")))
fmt.Println(bytes.Index(search_input, []byte("123"))) // will return -1
fmt.Println(bytes.Index(search_input, []byte("abcd")))
}
Output :
4 <------ index start counting from 0 ! therefore 和 is at index number 4
-1
0
Reference :
Advertisement
Something interesting
Tutorials
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+9k Golang : How to use Gorilla webtoolkit context package properly
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+14.9k Golang : Basic authentication with .htpasswd file
+10k CodeIgniter : Load different view for mobile devices
+12.3k Golang : Print UTF-8 fonts on image example
+19.7k Golang : Archive directory with tar and gzip
+16.3k Golang :Trim white spaces from a string
+5.2k Golang : Calculate half life decay example
+12.1k Golang : Split strings into command line arguments
+10.5k Golang : Create matrix with Gonum Matrix package example
+21.1k Golang : Convert(cast) string to rune and back to string example