简体   繁体   English

StreamReader C# 无法读取 å、ä、ö

[英]StreamReader C# does not read å, ä, ö

I have a StreamReader reading a file like below for reading a .csv file:我有一个StreamReader读取如下文件以读取.csv文件:

using (StreamReader sr = new StreamReader(filePath, System.Text.Encoding.GetEncoding("iso-8859-1")))
{
    string line = string.Empty;
    line = sr.ReadLine()
}

The first line of the file is: å ä ö Ü (for testing purposes).文件的第一行是: å ä ö Ü (用于测试目的)。 However, when I try to read the file C# does not read the characters as it should:但是,当我尝试读取文件 C# 时,它不会读取应有的字符:

在此处输入图像描述

Any idea why that is?知道为什么吗?

Remove encoding or select the right one.去掉右边的编码或select。 I am using this syntax without any problem我使用这种语法没有任何问题

    string str = string.Empty;
    using (StreamReader r = new StreamReader(@"C:\..."))
        str = r.ReadToEnd();

ouput输出

å ä ö Ü

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM