将ANSI值转换为字符 [英] Convert ANSI value to character

查看:112
本文介绍了将ANSI值转换为字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pi的ANSI值是182,ƒ是131.

我正在读取一个XMl文件,其中包含许多ANSI值,我必须显示为字符,即如果我通过131它应该给我是ƒ角色。



提前致谢

The ANSI value of Pi is 182,ƒ is 131.
I am reading a XMl file which contains a lots of ANSI values i have to display as character i.e if i pass 131 it should give me "ƒ" character.

Thanks in advance

推荐答案

感谢对问题的评论Afzaal,我意识到你可能意味着过时的Windows 1252编码: https://en.wikipedia.org/wiki/Windows-1252 [ ^ ]。



182 = 0xb6是ANSI和Unicode中的pilcrow sign('¶');和131 = 0x83在Unicode中是不中断,在通常称为ANSI的内容中未定义。



这里我们正处于一个微妙的角度。 ANSI作为一个字符集,并不确定。这个术语可能指的是不同的东西。请阅读: https://en.wikipedia.org/wiki/ANSI_character_set [ ^ ]。



同样时间,角色的术语ANSI在Unicode前版本的Windows版本中被广泛用作特定于Windows的术语,后来被重命名为使用现代版Windows支持的旧版非Unicode Windows字符编码的术语,用于备份兼容性,在一定程度上。请参阅上面的参考资料以及参考文章和MSDN文档。



我必须注意Windows充满了令人困惑的行话,不符合任何标准。甚至术语Unicode也常用于行话,因为编码UTF-16LE,它是用于在内存中表示Unicode字符/字符串的内部编码,它没有提供称其为Unicode的理由。其他UTF由其标准名称调用,但很少提及 endianness
与此相反.NET完全基于Unicode标准,它也是XML(支持许多字符集)的主要标准,因此也支持WPF和其他所有标准。您应该了解Unicode不是编码。 Unicode编码标准化为UTF,支持相同的字符集,没有任何排除;和XML 字符实体与UTF无关,它们直接指定Unicode 字符点



结论:您需要摆脱过时的编码并将所有内容转换为Unicode,并且只转换为Unicode。在.NET中,可以使用类 System.Text.Encoding 来完成(从MSDN文档中可以看出它的用法非常明显):

https://msdn.microsoft.com/en-us/ library / system.text.encoding%28v = vs.110%29.aspx [ ^ ]。



-SA
Thanks to the comment to the question by Afzaal, I realized that you probably mean obsolete encoding Windows 1252: https://en.wikipedia.org/wiki/Windows-1252[^].

And 182=0xb6 is the "pilcrow sign" ('¶') in both "ANSI" and Unicode; and 131=0x83 is "no break here" in Unicode and undefined in what is usually referred to as "ANSI".

Here we are coming to a delicate point. "ANSI", as a character set, is not something certain. This "term" may refer to different things. Please read about it: https://en.wikipedia.org/wiki/ANSI_character_set[^].

At the same time, the term "ANSI" for the character was extensively used as Windows-specific jargon word in pre-Unicode Windows versions, and later renamed as a term using for legacy non-Unicode Windows character encodings supported by modern versions of Windows for backup compatibility, to certain extent. See the reference above and the references article and MSDN documentation.

I have to note that Windows is full of confusing jargon words not meeting any standard. Even the term "Unicode" is routinely used in jargon sense, as the encoding UTF-16LE, which is the internal encoding use for representing Unicode characters/strings in memory, which provides no justification to call it "Unicode". Other UTFs are called by their standard names, but rarely mentioning endianness.
In contrast to that, .NET is fully based on Unicode standard which is also the main standard for XML (which supports many character sets), and hence WPF and everything else. You should understand that Unicode is not encoding. Unicode encodings are standardized as UTFs which support the same character repertoire, without any exclusions; and XML character entities have nothing to do with UTFs, they directly specify Unicode character points.

Conclusion: You need to get rid of the obsolete encoding and transcode everything in Unicode, and only to Unicode. In .NET, it can be done using the class System.Text.Encoding (its use is pretty obvious from MSDN documentation):
https://msdn.microsoft.com/en-us/library/system.text.encoding%28v=vs.110%29.aspx[^].

—SA


这篇关于将ANSI值转换为字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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