简体   繁体   English

Unicode转换为ASCII

[英]Unicode to ASCII

I have a Unicode : ¾àÖ'œ . 我有一个Unicode: ¾àÖ'œ

I need to convert this Unicode into ASCII. 我需要将此Unicode转换为ASCII。 I tried with the below code,but the output result is incorrect .For the Unicode '¾' output answer is 64. 我尝试使用以下代码,但是输出结果不正确。对于'¾'输出答案是64。

String as_pass = "¾àÖ‘œ";

li_passlen = as_pass.Length;

byte[] asciiBytes = new byte[li_passlen];

asciiBytes = Encoding.ASCII.GetBytes(as_pass); 

Please help me to solve this issue 请帮我解决这个问题

You are refering to so called "extended" ascii, which is group of encodings extending regular 7-bit ascii by 1 bit (sometimes even more). 您指的是所谓的“扩展” ASCII,这是一组将常规7位ASCII扩展1位(有时甚至更多)的编码。 One such encoding is iso-8859-1, which seems to be the one you need. iso-8859-1是一种这样的编码,它似乎是您需要的一种。 So to get result you expect, do: 因此,要获得您期望的结果,请执行以下操作:

asciiBytes = Encoding.GetEncoding("iso-8859-1").GetBytes(as_pass);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM