문제

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?

도움이 되었습니까?

해결책

Seems you need to use Unicodeencoding.

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

foreach (string s in lines) { Console.WriteLine(s); }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top