首页 新闻 会员 周边

Encoding 字符编码的问题

0
悬赏园豆:20 [已解决问题] 解决于 2008-06-23 15:48
socket.send 发送的字符串,如下 <br> strS = "6800000000000068010243C3D916" <br> Byte[] bytesSent = Encoding.Unicode.GetBytes(strS); <br> socket.Send(bytesSent, bytesSent.Length, 0); <br> <br> <br> 接收到的怎么是些这样的内容。而不是我发送的包. <br> 用别的测试工具发下去,接收的显示正常。 <br> &lt; &lt;--服务器已收到:(56)6 <br> &lt; &lt;--36&nbsp; 00&nbsp; 38&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 36&nbsp; 00&nbsp; 38&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 31&nbsp; 00&nbsp; 30&nbsp; 00&nbsp; 32&nbsp; 00&nbsp; 34&nbsp; 00&nbsp; 33&nbsp; 00&nbsp; 43&nbsp; 00&nbsp; 33&nbsp; 00&nbsp; 44&nbsp; 00&nbsp; 39&nbsp; 00&nbsp; 31&nbsp; 00&nbsp; 36&nbsp; 00&nbsp; <br> <br> <br> 可能是Encoding转换有问题,C#能用的编码都试了,还是不行。谁知道请指教,多谢了。 <br> Encoding.Unicode <br> ASCII <br> Default <br> UTF32 <br> UTF8 <br> UTF7 <br> 这些都试过,不行。
问题补充: 自已发,自已收是没问题可以用Encoding.Unicode.GetString再转换过来。现在是发给别人的程序,他们收到的不对,可能是我这边发的编码不对。 别的程序发6800000000000068010243C3D916,收到的也是6800000000000068010243C3D916,我的程序发过去就不是这个。
健2000的主页 健2000 | 初学一级 | 园豆:174
提问于:2008-06-23 09:21
< >
分享
最佳答案
0
36 00 38 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 36 00 38 00 30 00 31 00 30 00 32 00 34 00 33 00 43 00 33 00 44 00 39 00 31 00 36 00 这个序列是你服务器打印的还是其他工具打印的?这个序列是正确的,和下面代码转换 出来的字节序列是一样的。只不过是16进制表示。 strS = "6800000000000068010243C3D916" Byte[] bytesSent = Encoding.Unicode.GetBytes(strS);
eaglet | 专家六级 |园豆:17139 | 2008-06-23 12:02
其他回答(2)
0
Encoding.Unicode.GetString再转换过来。 发出去是byte字节数组,没问题的。
zeus2 | 园豆:92 (初学一级) | 2008-06-23 10:17
0

Encoding.Unicode 的意思,好象是 UTF16, 每个字符,不论中英文,都是用两位 byte 来表示。

老兄的意思,可能是要用 Encoding.UTF8 来处理。

杰克伦敦尘 | 园豆:274 (菜鸟二级) | 2013-03-03 10:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册