在C#控制台应用程序中打印ASCII线条艺术字符 [英] Print ASCII line art characters in C# console application

查看:141
本文介绍了在C#控制台应用程序中打印ASCII线条艺术字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让C#控制台应用程序从 http://www.asciitable.com/打印扩展的ASCII代码..我特别关注的是线条艺术人物:169、170、179-218.不幸的是,当我尝试时,最终得到218的Ú",并希望看到 http:中的其他字符://www.csharp411.com/ascii-table/.

I would like to have a C# console application print the extended ASCII Codes from http://www.asciitable.com/. In particular I am looking at the line art characters: 169, 170, 179-218. Unfortunately when I tried, I ended up getting 'Ú' for 218 and expect to see the other characters from http://www.csharp411.com/ascii-table/.

我知道ASCII仅指定字符代码0-127.我发现了另一篇文章引用了SetConsoleOutputCP(),但是无法使它在C#类中工作或找不到如何做的示例如此.

I'm aware that ASCII only specifies character codes 0 - 127. I found another post with a reference to SetConsoleOutputCP(), but was not able to get that to work in a C# class or find an example of how to do so.

是否可以在C#控制台应用程序中打印艺术线条字符?如果可以,有人可以提供示例或代码的URL吗?

Is it possible to print the line art characters in a C# console application? If it is can someone provide a URL to an example or the code?

推荐答案

一个小程序,用于修改Console.OutputEncoding属性使用的代码页以使用所需的字符:

A small program that modifies the codepage used by the Console.OutputEncoding property to use the characters you desire:

class Program
{
    static void Main(string[] args)
    {
        Console.OutputEncoding = System.Text.Encoding.GetEncoding(1252);
        Console.WriteLine((char) 169);
        Console.WriteLine((char) 170);

        for(char c = (char)179; c <= (char)218; ++c)
        {
            Console.WriteLine(c);
        }
    }
}

因此,我继续查找了与Unicode相类似的艺术作品.还有一些额外的字形可能对您有用.维基百科页面上列出了所有代码点.

So I went ahead and looked up the Unicode equivalents of the box art. There's a few extra glyphs that may be useful to you. That Wikipedia page lists all of their code points.

我将其组合起来进行尝试:

I've put together this to try them out:

class Program
{
    static void Main(string[] args)
    {
        for(int i = 0x2500; i <= 0x2570; i += 0x10)
        {
            for(int c = 0; c <= 0xF; ++c)
            {
                Console.Write((char) (i + c));
            }

            Console.WriteLine();
        }
    }
}

对我来说,很多字形只是作为?出现的,但是我们习惯于在旧ASCII游戏中看到的标准盒式字形确实对我而言.希望这些对您有用.

For me, quite a few glyphs simply come up as ?, but the standard box-art glyphs we're used to seeing in the old ASCII games do appear for me. Hopefully these will work for you.

这篇关于在C#控制台应用程序中打印ASCII线条艺术字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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