Reputation: 551
I am writing a .NET 5 console application in C#. One of the things I would like to be able to do is to display two specific Unicode characters: a full heart (♥
- Unicode number 2665) and an empty heart (♡
- Unicode number 2661). Thus:
const char emptyHeart = '\u2661';
const char fullHeart = '\u2665';
I assume I have that set properly, but for some reason the console is showing the emptyHeart
as a question mark instead of the proper character. Thus, for example, a string containing three fullHeart
s followed by four emptyHeart
s shows as ♥♥♥????
instead of the intended ♥♥♥♡♡♡♡
. Is this fixable without changing the Unicode characters (such as to filled and empty circles)? If so, how?
Upvotes: 1
Views: 829
Reputation: 29869
https://learn.microsoft.com/dotnet/api/system.console.outputencoding?view=net-5.0#notes-to-callers
Note that successfully displaying Unicode characters to the console requires the following:
- The console must use a TrueType font, such as Lucida Console or Consolas, to display characters.
- A font used by the console must define the particular glyph or glyphs to be displayed. The console can take advantage of font linking to display glyphs from linked fonts if the base font does not contain a definition for that glyph.
The default Windows console font, Consolas, does include a glyph for \u2665, but not for \u2661 as per the U+2660 row from https://www.fileformat.info/info/unicode/font/consolas/grid.htm.
Your only option, therefore, is to change the console's font to one that does support that glyph. However this is not a trivial operation; see "The following example shows how you can programmatically change the font from a raster font to Lucida Console" from https://learn.microsoft.com/dotnet/api/system.console#unicode-support-for-the-console (although Lucida Console doesn't support \u2661 either, so you'll have to find a font that does).
Upvotes: 1