如何在 Go 中将 [Size]byte 转换为字符串? [英] How do I convert [Size]byte to string in Go?
本文介绍了如何在 Go 中将 [Size]byte 转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在执行 md5.Sum()
后得到了一个大小合适的字节数组.
I have a sized byte array that I got after doing md5.Sum()
.
data := []byte("testing")
var pass string
var b [16]byte
b = md5.Sum(data)
pass = string(b)
我得到错误:
无法将 b(类型 [16] 字节)转换为字符串类型
cannot convert b (type [16]byte) to type string
推荐答案
你可以把它称为切片:
pass = string(b[:])
这篇关于如何在 Go 中将 [Size]byte 转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文