Saturday, April 4, 2009

C# - Convert byte[] to string by Encoding

A byte[] array is convertable to string using System.Text.Encoding class,
For this purpose there are other subclasses as follwoing too:

System.Text.ASCIIEncoding
System.Text.UnicodeEncoding
System.Text.UTF7Encoding
System.Text.UTF8Encoding

It's also possible to keep default encoding to get your string:


...
System.Text.Encoding myEnc = System.Text.Encoding.Default;
string strMacCmdPrm = myEnc.GetString( theByteArray );
...

Share/Bookmark

No comments: