byte[] 与string之间如何实现相互转换?

studyvc6 2006-12-31 12:36:35
如题。
byte [] data ; //长度 len=100;
String text;

如何相互转换?
...全文
238 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
heilong05 2007-02-28
  • 打赏
  • 举报
回复
string value="0x22, 0x25, 0xd3, 0xdd, 0xac, 0x34, 0x98, 0x2f, 0xa1, 0xa1, 0x52, 0xc9, 0x2c, 0xbc, 0x25, 0x66, 0x27, 0xa8, 0x34, 0x38, 0xa4, 0x91, 0x56, 0x89, 0x55, 0xee, 0xb6, 0x15, 0x3b, 0x12, 0x4f, 0xf4"

现在想让他成为:
byte[] value=={0x22, 0x25, 0xd3, 0xdd, 0xac, 0x34, 0x98, 0x2f, 0xa1, 0xa1, 0x52, 0xc9, 0x2c, 0xbc, 0x25, 0x66, 0x27, 0xa8, 0x34, 0x38, 0xa4, 0x91, 0x56, 0x89, 0x55, 0xee, 0xb6, 0x15, 0x3b, 0x12, 0x4f, 0xf4}

请问该如何转换。谢谢。
xbugirl 2006-12-31
  • 打赏
  • 举报
回复
byte[] buffer = System.Text.Encoding.Unicode.GetBytes(text); //转换到 byte
text = System.Text.Encoding.Unicode.GetString(buffer); //转换到 string
riluo 2006-12-31
  • 打赏
  • 举报
回复
Encoding.ASCII.GetBytes
Encoding.Utf8.GetBytes
Encoding.Unicode.GetBytes
madongxing 2006-12-31
  • 打赏
  • 举报
回复
楼上正解
xray2005 2006-12-31
  • 打赏
  • 举报
回复
jf
dr_lou 2006-12-31
  • 打赏
  • 举报
回复
byte[] by ;
UTF8Encoding data = new UTF8Encoding(true);
string str = data.GetString(by);
liujia_0421 2006-12-31
  • 打赏
  • 举报
回复
out:

happy new year
liujia_0421 2006-12-31
  • 打赏
  • 举报
回复
for example:

string text = "happy new year";
byte[] data = System.Text.Encoding.Unicode.GetBytes(text);
text = System.Text.Encoding.Unicode.GetString(data);
Console.WriteLine(text);
studyvc6 2006-12-31
  • 打赏
  • 举报
回复
我上网的电脑上没有.net,谁能帮我试试啊,看看是不是对的

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧