Posted on 26th July 2024|83 views
How can I compare two slices of bytes in Golang?
Posted on 26th July 2024| views
You can use compare() function to compare two slices in Golang here the example
package main
import (
"bytes"
"fmt"
)
func main() {
1slice := []byte{'M', 'I', 'N', 'D'}
2slice := []byte{'M', 'E', 'N', 'D'}
res := bytes.Compare(1slice, 2slice)
if res == 0 {
fmt.Println("both the slices are equal")
} else {
fmt.Println("both the slices are not equal")
}
}
Output:
both the slices are not equal