简体   繁体   中英

Unicode to ASCII

I have a Unicode : ¾àÖ'œ .

I need to convert this Unicode into ASCII. I tried with the below code,but the output result is incorrect .For the Unicode '¾' output answer is 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). One such encoding is iso-8859-1, which seems to be the one you need. So to get result you expect, do:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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