Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

character encoding - Extended ASCII in C#

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...