本文介绍了如何在Windows Forms C#中将扩展ASCII转换为十进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写Windows应用程序.将扩展的ASCII [128-256] 转换为其十进制等效值时遇到问题.
I am writing a windows application. am facing problem in converting Extended ASCII[128-256] to its decimal equivalent.
当我从jar文件中接收到扩展的ASCII字符(例如``say'')时,它将像这样:进入C#应用程序中.
when i receive the extended ASCII say for example "Œ" from a jar file, it comes into C# application like this : �.
我能知道如何将其转换为等效的十进制数[即]140.
Can i know how to convert this to its decimal equivalent [i.e] 140.
string textToConvert = "Œ";
Encoding iso8859 = Encoding.GetEncoding("iso-8859-1");
Encoding unicode = Encoding.Unicode;
byte[] srcTextBytes = iso8859.GetBytes(textToConvert);
byte[] destTextBytes = Encoding.Convert(iso8859,unicode, srcTextBytes);
char[] destChars = new char[unicode.GetCharCount(destTextBytes, 0, destTextBytes.Length)];
unicode.GetChars(destTextBytes, 0, destTextBytes.Length, destChars, 0);
System.String szchar = new System.String(destChars);
MessageBox.Show(szchar);
请帮助我.我应该如何进行?
Please help me. How should i proceed??
推荐答案
我认为您正在寻找类似的东西
I think you are looking for something like this
String str="œ";
var bytes = Encoding.GetEncoding("Windows-1252").GetBytes(s);
string binStr = string.Join("", bytes.Select(b => Convert.ToString(b, 2)));
int decimalEquivalent=Convert.ToInt32(binStr,2);
Console.WriteLine(decimalEquivalent);
这适用于ASCII [128-255]
this is working for ASCII [128-255]
这篇关于如何在Windows Forms C#中将扩展ASCII转换为十进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!