Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print a bullet character to the console?

This is my code:

Console.WriteLine("•");

Or this:

Console.WriteLine("\u2022");

The result (on my computer):

*beep*

The desired result:

How can I make the above character appear on my console?


I understand where the beep comes from, as the bullet is translated into an ASCII BELL character. This question came about while trying to understand more about codepage 437.

like image 853
Kendall Frey Avatar asked Sep 05 '14 01:09

Kendall Frey


2 Answers

This seems to solve the problem much easier than the other options listed. (And it's available now, even if it wasn't when the question was originally asked.)

Console.OutputEncoding = System.Text.Encoding.UTF8;
like image 96
John Fisher Avatar answered Nov 05 '22 09:11

John Fisher


I just remembered a Windows console mode that doesn't process ASCII codes such as the bell and linefeed. I need these functions:

[DllImport("kernel32.dll")]
static extern IntPtr GetStdHandle(int handle);

[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(IntPtr handle, int mode);

Before I try writing to the console, I do this:

SetConsoleMode(GetStdHandle(-11), 2);

This fetches a handle to the native screen buffer attached to stdout, and disables the ENABLE_PROCESSED_OUTPUT flag.

Console.WriteLine("•");

Output:

•♪◙

Whoops, that means it won't process the linefeed and carriage return that come from WriteLine.

Console.Write("•");

Output:

Bingo!

Now if I want to revert the console back to 'normal' mode before printing more text, I can do this:

SetConsoleMode(GetStdHandle(-11), 3);
like image 34
Kendall Frey Avatar answered Nov 05 '22 08:11

Kendall Frey