Golang bytes.IndexByte() function example
package bytes
IndexByte returns the index of the first instance of search key in search input. In case search key was not found in search input. It returns -1.
Golang bytes.IndexByte() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
fmt.Println(bytes.IndexByte([]byte("abcdef"), '5')) // return -1
fmt.Println(bytes.IndexByte([]byte("abcdef"), 'd')) // return index num of d..remember index start from 0
}
Output :
-1
3
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Golang : Convert an executable file into []byte example
+7.4k Golang : Check to see if *File is a file or directory
+14k Golang : Compress and decompress file with compress/flate example
+6.3k Javascript : Generate random key with specific length
+87.7k Golang : How to convert character to ASCII and back
+14k Golang : Reverse IP address for reverse DNS lookup example
+6.9k Golang : Normalize email to prevent multiple signups example
+30.5k Get client IP Address in Go
+19.1k Mac OSX : Homebrew and Golang
+6.2k Linux/Unix : Commands that you need to be careful about
+11.8k Golang : GTK Input dialog box examples
+12.1k Golang : Detect user location with HTML5 geo-location