how to read special character like é, â and others in C#

前端 未结 4 2085
旧巷少年郎
旧巷少年郎 2020-12-09 01:50

I can\'t read those special characters I tried like this

1st way #

string xmlFile = File.ReadAllText(fileName);

2nd way #

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 02:16

    You have to tell the StreamReader that you are reading Unicode like so

    StreamReader sr = new StreamReader(stream, Encoding.Unicode);
    

    If your file is of some other encoding, specify it as the second parameter

提交回复
热议问题