c#怎么把byte数组转换为字符串
2个回答
展开全部
有两张方法:
方法一:
//字符串转byte
string StringMessage = "How Are you?";
Console.WriteLine("{0}", StringMessage);
System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
Byte[] BytesMessage = ASCII.GetBytes(StringMessage);
//byte转字符串
Byte[] BytesMessage;
System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
String StringMessage = ASCII.GetString( BytesMessage );
方法二:
//字符串转UTF-8 byte
string StringMessage = "Hello World How Are you? Pi /u03C0 Yen /uFFE5";
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
Byte[] BytesMessage = UTF8.GetBytes(StringMessage);
//UTF-8 byte 转字符串
Byte[] BytesMessage;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
String StringMessage = UTF8.GetString( BytesMessage );
方法一:
//字符串转byte
string StringMessage = "How Are you?";
Console.WriteLine("{0}", StringMessage);
System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
Byte[] BytesMessage = ASCII.GetBytes(StringMessage);
//byte转字符串
Byte[] BytesMessage;
System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
String StringMessage = ASCII.GetString( BytesMessage );
方法二:
//字符串转UTF-8 byte
string StringMessage = "Hello World How Are you? Pi /u03C0 Yen /uFFE5";
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
Byte[] BytesMessage = UTF8.GetBytes(StringMessage);
//UTF-8 byte 转字符串
Byte[] BytesMessage;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
String StringMessage = UTF8.GetString( BytesMessage );
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询