C# Help reading foreign characters using StreamReader

后端 未结 10 1292
别那么骄傲
别那么骄傲 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:06

    I had the same problem and my solution was simple: instead of

    Encoding.ASCII
    

    use

    Encoding.GetEncoding("iso-8859-1")
    

    The answer was found here.

    Edit: more solutions. This maybe more accurate one:

    Encoding.GetEncoding(1252);
    

    Also, in some cases this will work for you too if your OS default encoding matches file encoding:

    Encoding.Default;
    

提交回复
热议问题