How to convert UTF-8 byte[] to string?

后端 未结 15 2487
迷失自我
迷失自我 2020-11-22 03:11

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

15条回答
  •  青春惊慌失措
    2020-11-22 03:49

    In adition to the selected answer, if you're using .NET35 or .NET35 CE, you have to specify the index of the first byte to decode, and the number of bytes to decode:

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

提交回复
热议问题