Last active
February 29, 2016 13:13
-
-
Save cyanife/9aee07c8d12c2f5c7b84 to your computer and use it in GitHub Desktop.
[C#] Write Unicode character in windows console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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