Frage

I am trying to create a command line program capable of outputting different languages.

Is there a way to set the encoding for outputting to the command line through Console.WriteLine?

I want to swap between utf-8 and shift-JIS and not assume the command shell program is in the right format.

Just to add more information about this. My current code reads in a file which has special characters:

"Fadó, fadó"

but the output doesn't properly display the special characters:

"Fado, fado"

I am simply using Console.WriteLine:

foreach (string s in lines)
{
     Console.WriteLine(s);
}

I have not figure out how to set the encoding for Console.WriteLine. Is it even possible, or is there an alternative that someone can point out?

War es hilfreich?

Lösung

Seems you need to use Unicodeencoding.

string[] lines = new[] { "Fadó", "fadó" };
Console.OutputEncoding = Encoding.Unicode;

foreach (string s in lines) { Console.WriteLine(s); }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top