无法将土耳其语字符从文本文件读取到字符串数组 [英] Can not read turkish characters from text file to string array

查看:72
本文介绍了无法将土耳其语字符从文本文件读取到字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用土耳其语进行某种句子处理,并且我正在使用文本文件作为数据库.但是我无法从文本文件中读取土耳其字符,因此无法正确处理数据.

I am trying to do some kind of sentence processing in turkish, and I am using text file for database. But I can not read turkish characters from text file, because of that I can not process the data correctly.

string[] Tempdatabase = File.ReadAllLines(@"C:\Users\dialogs.txt");
textBox1.Text = Tempdatabase[5];

输出:

推荐答案

您可以随意使用 Encoding .这最终可能会产生预期的结果,但请记住,这可能不适用于其他文件.

You can fiddle around using Encoding as much as you like. This might eventually yield the expected result, but bear in mind that this may not work with other files.

通常,默认情况下,C#使用Unicode处理字符串和文件.因此,除非您真的需要其他东西,否则应该尝试以下方法:

Usually, C# processes strings and files using Unicode by default. So unless you really need something else, you should try this instead:

在记事本(或任何其他程序)中打开您的文本文件,并将其另存为 UTF-8 文件.然后,您应该获得预期的结果,而无需对代码进行任何修改.这是因为C#使用保存文件时使用的编码读取文件.这是默认行为,应该首选.

Open your text file in notepad (or any other program) and save it as an UTF-8 file. Then, you should get the expected results without any modifications in your code. This is because C# reads the file using the encoding you saved it with. This is default behavior, which should be preferred.

将文本文件另存为UTF-8时,C#会将其解释为这样.

When you save your text file as UTF-8, then C# will interpret it as such.

这也适用于Visual Studio中的 .html 文件,如果您注意到它们显示不正确(用ASCII解析)

This also applies to .html files inside Visual Studio, if you notice that they are displayed incorrectly (parsed with ASCII)

这篇关于无法将土耳其语字符从文本文件读取到字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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