C #: Characters do not display well when in the console, why?

The figure below explains everything:

alt text http://img133.imageshack.us/img133/4206/accentar9.png

The textInput variable comes from File.ReadAllText(path);, and characters like: 'é è ... are not displayed. When I run UnitTest, everything is fine! I see them ... why?

+3
source share
3 answers

I don’t know why it works with NUnit, but I open the file with NotePad ++ and I see ANSI in the format. Now I switched to UTF-8 and it works.

I'm still wondering why it works with NUnit and not in the console? but at least it works now.

, , - , ANSI , NUNit ?

-1

.NET(System.IO.StreamReader ..) UTF-8 . , .

, , "ANSI". , Windows 1252, "". , Windows . , System.Text.Encoding.Default, .

/EDIT: , :

  • , .NET, .
  • , , "ANSI" , . "" , (, ).

, : :

string text = System.IO.File.ReadAllText("path", Encoding.GetEncoding(1252));

- System.Text.Encoding.

, Windows-1252 ( , , Notepad ++ "ANSI" ). , , NUnit. , NUnit - , NUnit (.. UTF-8).

, : "ANSI" " ". , ANSI . , ++ - , , ANSI.

() Windows. , , , , Windows . - Windows-1252.

+3

Try customizing the sessin console code output page with the chcp command . The code pages supported by windows are here , here , and here . Remember that the fundametnaly console is quite simple: it displays UNCICODE or DBCS characters, using a code page to display the displayed glyph.

+1
source

Source: https://habr.com/ru/post/1698435/


All Articles