Extended ASCII in C#

一笑奈何 提交于 2019-11-28 02:18:59

问题


I want to store some of the extended ascii characters into a dictionary for lookup but having little issue with getting the conversion.

The current method I have to store these characters works for all the non-graphical looking ascii characters 0x20 to 0xAF.

Current method:

private static void LoadAnsiTable()
{
    for (byte i = 0x20; i < 0xFE; i++)
    {
      AnsiLookup.Add(i, Convert.ToChar(i).ToString());
    }
}

but the 0xAF and on does not have the ░ ▒ ▓ │ ┤╡ ╢ etc it just has these funky letters.

Looking at this table http://www.asciitable.com/ for reference.

This works if I manually add it,

AnsiLookup.Add(0xB0, "░");

I would like to know how I can get those symbols captured in some kind of collection without having to manually add them all?


回答1:


I assume your "Extended ASCII" is actually code page 437:

Encoding cp437 = Encoding.GetEncoding(437);
byte[] source = new byte[1];
for (byte i = 0x20; i < 0xFE; i++)
{
    source[0] = i;
    AnsiLookup.Add(i, cp437.GetString(source));
}

Beware that this code page is not natively supported by the .NET Framework, so it might not be available on all systems.



来源:https://stackoverflow.com/questions/17619279/extended-ascii-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!