为什么当我用流读取器读取德语.txt文件时,德语字母会丢失? [英] Why when I read a german .txt file with a streamreader the german letters get lost?

查看:78
本文介绍了为什么当我用流读取器读取德语.txt文件时,德语字母会丢失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许制作字符串Unicode。



我在CodeProject上找到的谷歌翻译程序的类似问题...



我尝试过:



Maybe making the string Unicode.

Similar problem with a Google Translator program I found here on CodeProject...

What I have tried:

using (StreamReader SR = new StreamReader(@"C:\Users\john\Dropbox\germanWords.txt"))
            {
                while (!string.IsNullOrWhiteSpace(s=SR.ReadLine()))
                {
                    try
                    {
                        l.Add(new ListOfWordsApp.FormMain.wordAndMeaning(
                            s.Substring(0, s.IndexOf("-")),
                           s.Substring(s.IndexOf("-") + 1)));
                    }
                    catch
                    {
                        MessageBox.Show(s);
                    }
                }
            }

推荐答案

使用最简单的构造函数创建StreamReader时 - 提供只有文件路径 - 默认情况下打开它假设UTF8编码 - 如果你的文本文件没有用UTF8编码,那么任何非英语字符,如带有变音符号的字符都不太可能被正确选取。您可以指定编码: StreamReader构造函数(流,编码)(System.IO) ) [ ^ ]但我首先要仔细研究你的输入数据及其来源,然后才能确保你所看到的字符已经损坏。
When you create a StreamReader using the simplest constructor - providing only the filepath - it is opened by default assuming UTF8 encoding-if your text file is not encoded in UTF8 then it's unlikely that any "non-English" characters such as those with an umlaut will be picked up correctly. You can specify the encoding: StreamReader Constructor (Stream, Encoding) (System.IO)[^] but I'd start by having a good look at your input data and it's source before I went too far to makesure that the characters you arelooking for aren't already "corrupted".


这篇关于为什么当我用流读取器读取德语.txt文件时,德语字母会丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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