c# - 当文件的内容也带有希伯来字母时,如何使用 openFileDialog 打开文本文件?

标签 c# winforms

这是打开文件的代码:

private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Title = "Please Select A Text File Or A Word File To Open";
            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.FileName = null;
            openFileDialog1.Filter = "Text Or Word|*.txt;*.doc;*.docx";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            DialogResult result1 = openFileDialog1.ShowDialog();
            string file1 = openFileDialog1.FileName;
            if (result1 == DialogResult.OK)
            {
                string s = File.ReadAllText(file1);
                textBox1.Text = s;
            }
        }

这是文本文件的源内容:

שיעור ראשון : יצירת פרוייקט חדש:
-----------------------------

New> Android > Android Application Project

Application Name > שם האפליקציה כפי שהמשתמשים יראו אותה.

Project Name > שם הפרוייקט כפי שיופיע ב Eclipse ושם הספרייה.

这就是我在文本框中得到的内容:

����� ����� : ����� ������� ���:
-----------------------------

New> Android > Android Application Project

Application Name > �� ��������� ��� ��������� ���� ����.

Project Name > �� �������� ��� ������ � Eclipse ��� �������.

Package Name > ���� ����� �� ����� ���� ����� ������� ����� ������ : ExtractLightning ��� ����.

Minimum Required SDK > ������ ������ ����� �� �������� ���������� ��� ����� ������ �� � API LEVEL.

Target SDK > ������ ������ ����� �� ������ ������� ������ �� ��������� ���. ���� ����� �� ��������� ��� �� ������ ������ 

最佳答案

您需要将编码更改为 Windows-1255代码页(或其他代码页,如果您知道的话)。

Encoding enc = Encoding.GetEncoding("Windows-1255");
string s = File.ReadAllText(file1, enc);

关于c# - 当文件的内容也带有希伯来字母时,如何使用 openFileDialog 打开文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17444158/

相关文章:

c# - 背靠背 for 循环中的 int、short、byte 性能

vb.net - .NET 应用程序崩溃,没有调试信息

c# - 跟踪列数据更改以供高级分析师审查

c# - C# 中的用户控件与自定义控件

c# - 从 sqlite 查询时 DateTime 不正确

c# - .NET 中自定义事件的设计模式

c# - OpenFileDialog 不浏览.NET CF 下的文件夹

c# - Telerik RadCompression 问题 - 一段时间后页面丢失 View 状态

C# 将 'old' WinForms 转换为 Web 应用程序,还是在新平台上重写?

c# - 禁用事件从其代码中自行触发