Golang bytes.Compare() function example
bytes
Compare returns an integer comparing two byte slices lexicographically. See reference (1).
Golang bytes.Compare() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
fmt.Println(bytes.Compare([]byte{1}, []byte{2}))
fmt.Println(bytes.Compare([]byte{1}, []byte{1, 2}))
fmt.Println(bytes.Compare([]byte{1}, []byte{1}))
fmt.Println(bytes.Compare([]byte{1}, []byte{0}))
fmt.Println(bytes.Compare([]byte{2}, []byte{1, 2}))
}
Output :
-1
-1
0
1
1
Reference :
Advertisement
Something interesting
Tutorials
+7.7k Gogland : Where to put source code files in package directory for rookie
+19.8k Golang : Append content to a file
+6.2k Golang : Calculate US Dollar Index (DXY)
+4.3k Javascript : How to show different content with noscript?
+5.7k Golang : Struct field tags and what is their purpose?
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+5.8k Golang : List all packages and search for certain package
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+5.2k PHP : See installed compiled-in-modules
+9.6k Golang : How to extract video or image files from html source code