Unicode转换为ASCII [英] Unicode to ASCII
本文介绍了Unicode转换为ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Unicode:¾àÖ‘œ
.
I have a Unicode : ¾àÖ‘œ
.
我需要将此Unicode转换为ASCII.我尝试使用以下代码,但输出结果不正确.对于Unicode '¾'
输出答案为64.
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);
请帮助我解决此问题
推荐答案
您指的是所谓的扩展" ascii,它是一组将常规7位ascii扩展1位(有时甚至更多)的编码. iso-8859-1是一种这样的编码,它似乎是您所需要的一种.因此,要获得您期望的结果,请执行以下操作:
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);
这篇关于Unicode转换为ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文