扩展ASCII在C# [英] Extended ASCII in C#

查看:555
本文介绍了扩展ASCII在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些扩展ascii字符存储到字典中查找,但对于获取转换没有什么问题。



当前方法我必须存储这些



当前方法:

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

但是0xAF和on没有░▒



查看此表 http://www.asciitable.com/ 以供参考。



如果我手动添加,

  AnsiLookup.Add(0xB0,░); 

我想知道如何获得这些符号在某些集合中捕获,

我假设你的扩展ASCII实际上是代码页437

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

请注意,此代码页本身不受.NET Framework支持,因此它可能不是在所有系统上都可用。


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?

解决方案

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.

这篇关于扩展ASCII在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆