如何读取特殊字符,如E,A等人在C# [英] how to read special character like é, â and others in C#

查看:197
本文介绍了如何读取特殊字符,如E,A等人在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法阅读这些特殊字符
我想这样

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

1的方式#

string xmlFile = File.ReadAllText(fileName);



第二种方法#

2nd way #

FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
StreamReader r = new StreamReader(fs);
string s = r.ReadToEnd();



不过,这两个语句不明白这些特殊字符。
我应该如何读?

But both statements don't understand those special characters. How should I read?

更新###

我也尝试用

string xmlFile = File.ReadAllText(fileName, Encoding. );



但还是不理解那些特殊字符。

but still don't understand those special characters.

推荐答案

有作为特殊字符没有这样的事。那些什么都可能从LATIN1集(ISO-8859-1)扩展ASCII字符。
你可以阅读那些通过显式编码到流器(否则将承担UTF8)

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();

这篇关于如何读取特殊字符,如E,A等人在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆