如何将 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);