byte [] - >串 [英] byte[] -> string

查看:85
本文介绍了byte [] - >串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将byte []转换为字符串?

有什么想法吗?


Andrea

解决方案

Andrea,

string text =(new System.Text.ASCIIEncoding())。GetString(byte []); < br $>
RF


" Andrea" < andreno_spamalmieri @ enmo_spamm>在消息中写道

新闻:e9 ************* @ TK2MSFTNGP09.phx.gbl ...

我该如何转换一个字节[]到一个字符串?
任何想法?

Andrea



" Andrea" < andreno_spamalmieri @ enmo_spamm>在消息中写道

新闻:e9 ************* @ TK2MSFTNGP09.phx.gbl ...

我该如何转换一个字节[]到一个字符串?
任何想法?

Andrea




如何在字节数组中编码字符?您需要检查

System.Text.Encoding类及其相关类:

System.Text.ASCIIEncoding,System.Text.UnicodeEncoding。这是一个基本的

示例,如果字节数组是ASCII:

System.Text.ASCIIEncoding AE = new System.Text.ASCIIEncoding();

byte [] ByteArray = {69,110,99,111,100,105,110,103,32,83,116,

114,105,110, 103,46};

char [] CharArray = AE.GetChars(ByteArray);

string s = new string(CharArray);

MessageBox.Show(s);


Erik




" Andrea" < andreno_spamalmieri @ enmo_spamm>在消息中写道

新闻:e9 ************* @ TK2MSFTNGP09.phx.gbl ...

我该如何转换一个字节[]到一个字符串?
任何想法?

Andrea




Encoding.ASCII.GetString(byteArray);


how can I convert a byte[] to a string ?
Any idea?

Andrea

解决方案

Andrea,

string text = (new System.Text.ASCIIEncoding()).GetString(byte[]);
RF

"Andrea" <andreno_spamalmieri@enmo_spamm> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...

how can I convert a byte[] to a string ?
Any idea?

Andrea



"Andrea" <andreno_spamalmieri@enmo_spamm> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...

how can I convert a byte[] to a string ?
Any idea?

Andrea



How are the characters encoded in the byte array? You need to examine the
System.Text.Encoding class and its related classes:
System.Text.ASCIIEncoding, System.Text.UnicodeEncoding. Here''s a basic
example, if the byte array is ASCII:

System.Text.ASCIIEncoding AE = new System.Text.ASCIIEncoding();
byte[] ByteArray = { 69, 110, 99, 111, 100, 105, 110, 103, 32, 83, 116,
114, 105, 110, 103, 46 };
char[] CharArray = AE.GetChars(ByteArray);
string s = new string(CharArray);
MessageBox.Show(s);

Erik



"Andrea" <andreno_spamalmieri@enmo_spamm> wrote in message
news:e9*************@TK2MSFTNGP09.phx.gbl...

how can I convert a byte[] to a string ?
Any idea?

Andrea



Encoding.ASCII.GetString(byteArray);


这篇关于byte [] - &gt;串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆