I know there are questions like this already: How do I convert [Size]byte to string in Go?, but my questions is "how do I convert []byte WITH ZERO VALUES to string"
package main
import (
"fmt"
"strings"
)
func main() {
a := make([]byte, 16)
r := strings.NewReader("test")
_, _ = r.Read(a)
b := "test"
fmt.Println(string(a), b)
fmt.Println(string(a) == b)
fmt.Println(len(string(a)), len(b))
fmt.Println(a, []byte(b))
}
The code above prints:
test test
false
16 4
[116 101 115 116 0 0 0 0 0 0 0 0 0 0 0 0] [116 101 115 116]
As you can see the zero values in a
caused inequality between a
and b
, how should I treat them? How can I compare the two correctly?