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

冷暖自知 提交于 2019-11-28 08:07:14

There is no such thing as "special character". What those likely are is extended ascii characters from the latin1 set (iso-8859-1). You can read those by supplying encoding explicitly to the stream reader (otherwise it will assume UTF8)

using (StreamReader r = new StreamReader(fileName, Encoding.GetEncoding("iso-8859-1")))
    r.ReadToEnd();
StreamReader sr = new StreamReader(stream, Encoding.UTF8)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!