简体   繁体   English

从文本文件中读取丹麦语字符

[英]Reading Danish characters from text files

I am trying to read text files that contains some danish characters. 我正在尝试阅读包含一些丹麦字符的文本文件。 I have found a few ways to do it using different types of encoding but the examples I have seen are reading just one file. 我找到了几种使用不同类型编码的方法,但我看到的例子只是读取一个文件。 This is what I have so far. 这就是我到目前为止所拥有的。

//search directory for all .txt files
foreach (string files in Directory.GetFiles(@"C:\ftp\inbox", "*.txt"))
{     
    //The 'using' command close connection when it is done
    using (var reader = new StreamReader(File.OpenRead(files)))               
    {
        // Handle contents
    }
}

My problem is all the characters are being read as . 我的问题是所有字符都被读作 。 I need them to be read in as they are. 我需要他们按原样阅读。

I resolved the issue by changing: 我通过改变来解决这个问题:

using (var reader = new StreamReader(File.OpenRead(files)))

into

using (var reader = new StreamReader(files, System.Text.Encoding.GetEncoding("iso-8859-1"))) 

and now the danish characters are read in as they should be. 现在丹麦人的角色应该被读入。

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

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