如何将 UTF-8 字节 [] 转换为字符串 [英] How to convert UTF-8 byte[] to string
本文介绍了如何将 UTF-8 字节 [] 转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 byte[]
数组,它是从我碰巧知道包含 UTF-8.
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?
在幕后,它应该只是一个分配和一个memcopy,所以即使没有实现,也应该是可能的.
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);
这篇关于如何将 UTF-8 字节 [] 转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文