小编Sil*_*deh的帖子

在C#中合并2个文本文件

首先,我想提一下,我几天前才开始学习C#,所以我对它的了解有限.

我正在尝试创建一个程序,该程序将解析用户输入的某些短语的文本文件,然后将它们输出到新的文本文档中.

目前,我有一个程序搜索原始输入文件并收集用户输入的选定文本,处理这些行,创建新的文本文件,然后将它们合并在一起,然后删除它们.

我猜这不是创建这个的最有效的方法,但我只是创建它并让它以逻辑庄园工作,让我理解为新手.

代码如下;

private void TextInput1()
    {
        using (StreamReader fileOpen = new StreamReader(txtInput.Text))
        {
            using (StreamWriter fileWrite = new StreamWriter(@"*DIRECTORY*\FIRSTFILE.txt"))
            {
                string file;
                while ((file = fileOpen.ReadLine()) != null)
                {
                    if (file.Contains(txtFind.Text))
                    {
                            fileWrite.Write(file + "\r\n");
                    }
                }
            }
        }
    }

    private void TextInput2()
    {
        using (StreamReader fileOpen = new StreamReader(txtInput.Text))
        {
            using (StreamWriter fileWrite = new StreamWriter(@"*DIRECTORY*\SECONDFILE.txt"))
            {
                string file;
                while ((file = fileOpen.ReadLine()) != null)
                {
                    if (file.Contains(txtFind2.Text))
                    {
                        fileWrite.Write("\r\n" + file);
                    }
                }
            }
        } …
Run Code Online (Sandbox Code Playgroud)

c# merge file

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

file ×1

merge ×1