如何为byte []转换为字符串? [英] How to convert byte[] to string?

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

问题描述

我有一个从我碰巧知道的文件加载的字节[] 数组包含的 UTF-8 。在一些调试code,我需要将其转换为字符串。是否有一个班轮,将做到这一点?

根据覆盖它应该只是一个分配和的存储器复制的,所以即使不实施,应该是可行的。

解决方案

 字符串结果= System.Text.Encoding.UTF8.GetString(字节阵列);
 

I have a byte[] array that is loaded from a file that I happen to known contains UTF-8. In some debugging code, I need to convert it to a string. Is there a one liner that will do this?

Under the covers it should be just an allocation and a memcopy, so even if it is not implemented, it should be possible.

解决方案

string result = System.Text.Encoding.UTF8.GetString(byteArray);

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

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