Reputation: 29461
This is so trivial it's going to sound silly, but please bear with me.
I used to be able to draw ASCII art smiley faces similar to this post by doing something like:
Console.Write((char)1);
Back when I did this on Windows XP/7, the console was not able to render the character by default. I got around this encoding issue by using this special encoding:
Console.OutputEncoding = System.Text.Encoding.GetEncoding(1252);
Now that I'm trying this out in Windows 10, I am getting this weird question mark character which is reminiscent of the original encoding problem:
Has something changed in the Windows 10 console to cause this problem? How can I fix it?
Upvotes: 2
Views: 2459
Reputation: 899
Try using the Unicode character
char c = '\u263a';
Console.WriteLine (c.ToString());
Upvotes: 1
Reputation: 354704
Note that (char)1
would only work with the OEM codepage 437. This worked well in DOS applications, but on Windows the approach is slightly trickier, especially since U+0001 does not represent a smiley face. U+263A does. So the correct way is actually:
Console.WriteLine((char)0x263A);
And you may have to explicitly set your output encoding to Unicode, or UTF-8 to make it show up, otherwise the character passes through a few character set translations along the way, depending on your console window settings:
Console.OutputEncoding = Encoding.Unicode;
Upvotes: 2
Reputation: 109732
This works for me on Windows 10:
public static void Main()
{
Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.WriteLine("☺");
}
Upvotes: 1