Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert byte[] to char[]

How do I convert a byte array to a char array in C#?

like image 894
saikamesh Avatar asked Mar 25 '11 10:03

saikamesh


2 Answers

System.Text.Encoding.ChooseYourEncoding.GetString(bytes).ToCharArray(); 

Substitute the right encoding above: e.g.

System.Text.Encoding.UTF8.GetString(bytes).ToCharArray(); 
like image 62
spender Avatar answered Sep 21 '22 07:09

spender


You must know the source encoding.

string someText = "The quick brown fox jumps over the lazy dog."; byte[] bytes = Encoding.Unicode.GetBytes(someText); char[] chars = Encoding.Unicode.GetChars(bytes); 
like image 43
Brett Avatar answered Sep 19 '22 07:09

Brett