Golang bytes.Equal() function example

package bytes

Equal returns a boolean reporting whether the given inputs are the same length and contain the same bytes. A nil argument is equivalent to an empty slice.

Golang bytes.Equal() 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 :

false

true

true

Advertisement