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/.
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.
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?
Try this: char c = 'a'; // or whatever your character is printf("%c %d", c, c); The %c is the format string for a single character, and %d for a digit/integer. By casting the char to an integer, you'll get the ascii value.
#include <stdio. h> #include <string. h> int main() { int e; char name[100] = ""; // Allow for up to 100 characters printf("Enter a name : \n"); // scanf("%c", &name); // %c reads a single character scanf("%99s", name); // Use %s to read a string!
Then, how to print character? We can use cast type here, by casting into char we are able to get result in character format. We can use cout<<char(65) or cout<<char(var), that will print 'A'. (65 is the ASCII value of 'A').
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);
}
}
}
EDIT:
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();
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With