C# Help reading foreign characters using StreamReader

后端 未结 10 1290
别那么骄傲
别那么骄傲 2020-11-29 02:46

I\'m using the code below to read a text file that contains foreign characters, the file is encoded ANSI and looks fine in notepad. The code below doesn\'t work, when the fi

10条回答
  •  粉色の甜心
    2020-11-29 03:07

    Using Encoding.Unicode won't accurately decode an ANSI file in the same way that a JPEG decoder won't understand a GIF file.

    I'm surprised that Encoding.Default didn't work for the ANSI file if it really was ANSI - if you ever find out exactly which code page Notepad was using, you could use Encoding.GetEncoding(int).

    In general, where possible I'd recommend using UTF-8.

提交回复
热议问题