文本文件-ID比对问题

对于一些文本文件里面的内容进行,文本捡漏的问题写的一个处理程序
首先先创建一个程序框
如图:![在这里插入图片描述](https://img-blog.csdnimg.cn/79114a589f1344b59d143f21e668b3e2.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bCP5p2J5p2JOTcxMTE1,size_11,color_FFFFFF,t_70,g_se,x_16)

在这里插入图片描述

在这里插入图片描述

如下代码段:
在这里插入代码片
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 文件_ID比较
{
    public partial class index : Form
    {
        Dictionary<string, string> openWith1 = new Dictionary<string, string>();
        Dictionary<string, string> openWith2 = new Dictionary<string, string>();
        private static int sum = 1;
        private static string str = "";
        public index()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择标准ID的文件";
            fileDialog.Filter = "所有文件(*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;

                textBox1.Text = file;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择比对ID的文件";
            fileDialog.Filter = "所有文件(*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;

                textBox2.Text = file;
            }
        }
        private void start_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
            {
                MessageBox.Show("您还未指定操作文件","温馨提示");
            }
            else
            {
                timer.Start();
            }
        }
        private void Flie_id1(string file_path)
        {
            int i = 0;

            try
            {
                mess.Text = "加载标准文件中";

                string str = File.ReadAllText(file_path, System.Text.Encoding.Default);

                string[] str_temp = str.Split(new char[] { '\n' });

                while (i < str_temp.Length - 1)
                {
                    Console.WriteLine(str_temp[i]);

                    if (str_temp[i].Substring(0, 1).Equals(";") || str_temp[i].Length == 1 || str_temp[i].Length < 29 || openWith1.ContainsKey(str_temp[i].Substring(0, 19)) || str_temp[i].Substring(0, 2) != "0x")
                    {
                        i++;

                        continue;
                    }
                    else
                    {
                        string[] sArray = Regex.Split(str_temp[i], ",    ", RegexOptions.IgnoreCase);

                        openWith1.Add(sArray[0].Trim().ToUpper(), str_temp[i]);

                        sum++;

                        i++;
                    }
                }
            }
            catch
            {
                MessageBox.Show("文件读取:" + i.ToString() + "行出现问题", "温馨提示");
            }
        }
        private void Flie_id2(string file_path)
        {
            int i = 0;

            try
            {
                mess.Text = "加载标准文件中";

                string str = File.ReadAllText(file_path, System.Text.Encoding.Default);

                string[] str_temp = str.Split(new char[] { '\n' });

                while (i < str_temp.Length - 1)
                {
                    if (str_temp[i].Substring(0, 1).Equals(";") || str_temp[i].Length == 1 || str_temp[i].Length < 29 || openWith2.ContainsKey(str_temp[i].Substring(0, 19)) || str_temp[i].Substring(0, 2) != "0x")
                    {
                        i++;

                        continue;
                    }
                    else
                    {
                        string[] sArray = Regex.Split(str_temp[i], ",    ", RegexOptions.IgnoreCase);

                        openWith2.Add(sArray[0].Trim().ToUpper(), str_temp[i]);

                        sum++;

                        i++;
                    }
                }
            }
            catch
            {
                MessageBox.Show("文件读取:" + i.ToString() + "行出现问题", "温馨提示");
            }
        }
        private void stop_Click(object sender, EventArgs e)
        {
            Flie_id1(textBox1.Text);

            Flie_id2(textBox2.Text);

            mess.Text = "文件加载完毕";

            ProgressBar.Maximum = sum;

            start.Enabled = true;

            stop.Enabled = true;
        }
        private void timer_Tick(object sender, EventArgs e)
        {
            mess.Text = "正在对比";

            foreach (string key in openWith1.Keys)
            {
                if (!openWith2.ContainsKey(key))
                {
                    str += openWith1[key] + "\n";
                }
                ProgressBar.Value += ProgressBar.Step;
            }

            ProgressBar.Value = ProgressBar.Maximum;

            mess.Text = "对比完成";

            start.Enabled = false;

            stop.Enabled = true;
            
            File.WriteAllText(textBox3.Text, str);

            openWith1.Clear();

            openWith2.Clear();

            timer.Stop();
        }

        private void index_Load(object sender, EventArgs e)
        {
            textBox3.Text = "FILE_ID.TXT";
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

️公子

有帮助的,请多支持我哦

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值