Golang bytes.Count() function example

package bytes

Count counts the number of non-overlapping instances of search key in given input

Golang bytes.Count() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 search_input := []byte("abcdefghidefdef")

 key_slice := []byte("abc")

 key_slice2 := []byte("xyz")

 fmt.Println(bytes.Count(search_input,key_slice))
 fmt.Println(bytes.Count(search_input,key_slice2))

 fmt.Println(bytes.Count(search_input,[]byte("def")))
 }

Output :

1

0

3

Advertisement