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 :

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

Advertisement