Skip to content

Instantly share code, notes, and snippets.

@cyanife
Last active February 29, 2016 13:13
Show Gist options
  • Save cyanife/9aee07c8d12c2f5c7b84 to your computer and use it in GitHub Desktop.
Save cyanife/9aee07c8d12c2f5c7b84 to your computer and use it in GitHub Desktop.
[C#] Write Unicode character in windows console.
using System.Runtime.InteropServices;
using System.IO;
namespace foo
{
class bar
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetConsoleOutputCP(int newcp);
static void Main(string[] args)
{
bool ok = SetConsoleOutputCP(65001);
Stream uniconstream = Console.OpenStandardOutput();
StreamWriter uniconstrwr = new StreamWriter(uniconstream, Encoding.UTF8, 500);
uniconstrwr.AutoFlush = true;
Console.SetOut(uniconstrwr);
Console.Write("\b \b"); // clear UTF preamble
Console.WriteLine( "test '\u20ac' '\u263a' '\u266b' '\u2126' end." );
Console.WriteLine("♠♤♥♡♦♢♣♧");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment