ASCII扩展为C#字符串 [英] ASCII Extended in C# string
问题描述
我如何在C#中创建一个字符串以接受不可打印的ASCII扩展字符,例如•,因为当我尝试将•放入字符串中时,它只能给出一个空格或空值.
How do I make a string in C# to accept non printable ASCII extended characters like • , cause when I try to put • in a string it just give a blank space or null.
推荐答案
扩展ASCII只是将8个高位设置为不同值的ASCII.
Extended ASCII is just ASCII with the 8 high bits set to different values.
问题在于,没有任何委员会批准扩展ASCII的标准.那里有很多变体,无法告诉您使用的是什么.
The problem lies in the fact that no commission has ratified a standard for extended ASCII. There are a lot of variants out there and there's no way to tell what you are using.
现在C#使用UTF-16编码,该编码将与您所使用的任何扩展ASCII码不同.
Now C# uses UTF-16 encoding which will be different from whichever extended ASCII you are using.
您将必须找到匹配的Unicode字符并将其显示如下
You will have to find the matching Unicode character and display it as follows
string a ="\u2649" ; //where 2649 is a the Unicode number
Console.write(a) ;
或者,您可以找出文件使用的编码方式,并像这样使用 例如.编码Windows-1252:
Alternatively you could find out which encoding your files use and use it like so eg. encoding Windows-1252:
Encoding encoding = Encoding.GetEncoding(1252);
和UTF-16
Encoding enc = new UnicodeEncoding(false, true, true);
并使用
Encoding.Convert (Encoding, Encoding, Byte[], Int32, Int32)
详细信息位于此处
这篇关于ASCII扩展为C#字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!