如何从windows-1252转换为ascii扩展 [英] How do I convert from windows-1252 to ascii extended

查看:101
本文介绍了如何从windows-1252转换为ascii扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试转换具有特殊字符¤的字符串。我的默认编码是Windows-1252。 char代码是164( Windows-1252 )但在Ascii Extended中,char代码164是ñ( Ascii表)。我遇到的问题是,在我从Windows-1252转换为Ascii之后,我在输出中得到 而不是ñ。我做错了什么?



我的尝试:



这是我的代码

I am trying to convert a string which has a special character ¤. The default encoding I have is Windows-1252. And the char code is 164 ( Windows-1252) but in Ascii Extended, char code 164 is ñ ( Ascii Table). The problem i am running into is that after i have converted from Windows-1252 to Ascii, i get � in the output instead of ñ. What am i doing wrong ?

What I have tried:

Here is my code

var input = "La Pe¤a";

var extAscii = Encoding.GetEncoding(437);

Encoding win1252 = Encoding.GetEncoding(1252);

var bytes1252 = win1252.GetBytes(input);

byte[] output = Encoding.Convert(Encoding.GetEncoding(1252), Encoding.GetEncoding(437),bytes1252);

Console.WriteLine(extAscii.GetString(output));
Console.ReadLine();





感谢您的帮助。



thanks for you help.

推荐答案

输出是对数据的解释。检查有问题的char是不是值164还是输出问题。也许控制台只能显示ascii。

The output is an interpretation of the data. Check if the problematic char isnt the value 164 or if it is an output problem. Maybe the console can only show ascii.
String input = "La Pe¤a";

Encoding extAscii = Encoding.GetEncoding(437);
Encoding win1252 = Encoding.GetEncoding(1252);

var bytes1252 = win1252.GetBytes(input);

byte[] output = Encoding.Convert(win1252, extAscii, bytes1252);//use of the objects
int problem = output[5];//check for 164

来自 Microsoft 的一些其他示例代码。

Some additional sample code from Microsoft.


好的,我有一个解决方案。现在,我不知道为什么我在下面进行以下转换时会得到15分。



Ok, i have a solution. For now, i don't know why i get 15 when i do the following conversion below.

String input = "La Pe¤a";

Encoding extAscii = Encoding.GetEncoding(437);
Encoding win1252 = Encoding.GetEncoding(1252);

var bytes1252 = win1252.GetBytes(input);

byte[] output = Encoding.Convert(win1252, extAscii, bytes1252);//use of the objects
int problem = output[5];//check for 164





所以我决定做的是从asci转换为asci



so what i decided to do was to convert from asci to asci

byte[] output = Encoding.Convert(extAscii, extAscii, bytes1252);//use of the objects
int problem = output[5];//check for 164





这就是我在ascii中得到164的原因ñ



And that is how i get 164 which in ascii is ñ


这篇关于如何从windows-1252转换为ascii扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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