Golang bytes.EqualFold() function example

package bytes

EqualFold reports whether the given inputs, interpreted as UTF-8 strings, are equal under Unicode case-folding.

Golang bytes.EqualFold() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 slice1 := []byte("世界")

 slice2 := []byte("xyz")

 slice3 := []byte("世界")

 fmt.Println(bytes.EqualFold(slice1, slice2))

 fmt.Println(bytes.EqualFold(slice1, slice3))

 fmt.Println(bytes.EqualFold(slice2,[]byte("XYZ"))) // big cap and small cap
 }

Output :

false

true

true

Reference :

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

Advertisement