How to emit UTF-8 from console mode program?

  • Thread starter Siegfried Heintze
  • Start date
S

Siegfried Heintze

The following perl program prints the russian alphabet in Cryllic when I use
the urxvt console from cygwin. It seems to understand UTF-8 better than
cmd.exe.

perl -wle "binmode STDOUT, q[:utf8]; print chr() for 0x410 .. 0x430;"

How can I translate this program to C# and write a console mode C# program
that emits UTF-8 and displays the proper Cryllic glyphs? I don't care what
console it works with, cmd.exe or urxvt are fine.
 
M

Marc Gravell

I don't know how I would check it, but you could try changing the
Console.OutputEncoding. However, I suspect you might need to
OpenStandardOutput() and write directly to the Stream; something like:

using (StreamWriter writer = new StreamWriter(
Console.OpenStandardOutput(),
new UTF8Encoding(false))) // no BOM
{
// write your glyphs to "writer"
}

Marc
 
A

Alhambra Eidos Desarrollo

using (StreamWriter writer = new StreamWriter(
Console.OpenStandardOutput(),
new UTF8Encoding(false))) // no BOM
{
// write your glyphs to "writer"
}

What differences UTF-8 without BOM and with BOM ??

Thanks.
 
M

Marc Gravell

The BOM (byte order mark) is a few bytes at the start that indicate
which flavour of unicode it is... useful in a file, but for a console
I /suspect/ that it is unnecessary... try it with/without - see which
works better.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top