C#代码片段 导入一个txt文本,快速过滤重复行

来源:互联网 发布:硬盘raw格式化软件 编辑:程序博客网 时间:2024/04/30 10:25

导入一个txt文本,快速过滤重复行

HashSet<string> strlist = new HashSet<string>();if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK){                //                string filename = openFileDialog1.FileName;                int repcnt=0;                string[] lines = System.IO.File.ReadAllLines(filename,System.Text.Encoding.Default);                for(int i=0;i<lines.Length;i++){                    if(lines[i]!=""){                        if( !strlist.Add(lines[i])){                            repcnt++;                         }                    }                 }                if(repcnt>0){                    SetLog("过滤重复 " + repcnt);                }                 SetLog("导入数量 " + strlist.Count);                            } 


0 0
原创粉丝点击