如何在Go中将[Size]字节转换为字符串? [英] How do I convert [Size]byte to string in Go?

查看:87
本文介绍了如何在Go中将[Size]字节转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做 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)

我得到错误:

I get the error:


无法将b(type [16] byte)转换为字符串型

cannot convert b (type [16]byte) to type string


推荐答案

您可以将其称为切片:

You can refer to it as a slice:

pass = string(b[:])

这篇关于如何在Go中将[Size]字节转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆