Encoding.GetEncoding(437).GetString()错误? [英] Encoding.GetEncoding(437).GetString() bug?

查看:243
本文介绍了Encoding.GetEncoding(437).GetString()错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下测试程序

char c = '§';
Debug.WriteLine("c: " + (int)c);

byte b = Encoding.GetEncoding(437).GetBytes("§")[0];
Debug.WriteLine("b: " + b);

char c1 = Encoding.GetEncoding(437).GetString(new byte[] { 21 })[0];
Debug.WriteLine("c1: " + (int)c1);

这将产生以下结果:

c: 167
b: 21
c1: 21

我可以看到此处 GetBytes正常工作

167 unicode => CP437中的21

但GetString不起作用
CP437中的
21 => Unicode中的21

As I can see here GetBytes is working correctly
167 in unicode => 21 in CP437
but GetString is not working
21 in CP437 => 21 in unicode

这是是错误还是我的错误?

Is this a bug or my mistake?

推荐答案

CP437对于0-31范围内的字符不是双向的。如Wikipedia页面中所述,您已链接:

CP437 is not "two-way" for characters in the range 0-31. As stated in the Wikipedia page you linked:


对于许多用途,代码范围为0到31,代码127将为
不产生这些符号。其中的一些(或全部)将被解释为ASCII控制字符

For many uses, the codes in the range 0 to 31 and the code 127 will not produce these symbols. Some (or all) of them will be interpreted as ASCII control characters.

将Unicode字符映射到受支持的CP437此范围内的字符有效,但反之则不行。例如,以字节13和10表示的字符为例:很有可能,如果将它们放入CP437字符串中,则实际上希望保留回车符和换行符,而不转换为项目符号和音符。这是正常现象:不是错误。

Mapping an Unicode character to a supported CP437 character that is in this range works, but not the other way around. For example, take characters represented by bytes 13 and 10: chances are that if you got them inside a CP437 string, you actually want carriage return and line feed characters to be preserved, and not converted to a bullet and a music note. This behavior is normal: it's not a bug.

这篇关于Encoding.GetEncoding(437).GetString()错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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