字符转换问题

toball 2004-10-20 03:24:50
string str= "111aaabb江水流";
怎样把一个既有字母又有汉字的字符串转为字节码(byte[]类型)
...全文
114 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
syqhero 2004-10-20
  • 打赏
  • 举报
回复
sendByte = System.Text.Encoding.Unicode.GetBytes(str);
这样就可以了,我试验过了。
kkeemmgg 2004-10-20
  • 打赏
  • 举报
回复
byte[] by=Encoding.GetEncoding("GB2312").GetBytes(str);
toball 2004-10-20
  • 打赏
  • 举报
回复
各位同仁,你们在做网络编程的时候,发送既有英文又有汉字的字符串的包的时候是怎么做的
toball 2004-10-20
  • 打赏
  • 举报
回复
不行,
我如果用
byte[] sendByte =new byte[256];
string str="aa江"
sendByte = System.Text.Encoding.ASCII.GetBytes(str);
sendByte的长度变成只有三个字节了,可是"aa江"是四个字节才对
t0h 2004-10-20
  • 打赏
  • 举报
回复
System.Text.Encoding.GetEncoding().GetBytes(str);

可否?

110,561

社区成员

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

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

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