欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

重复行过滤工具(.NET源码+工具)

程序员文章站 2022-05-07 21:13:21
重复行过滤工具(vs2010.NET源码+工具) 写的很差:( 凑合用:) 今天为了项目的一个重复文本过滤写了个工具估计这玩意以后也会用到先发到这里共享一下给大家 俺编程水平很差...

重复行过滤工具(vs2010.NET源码+工具) 写的很差:( 凑合用:)
今天为了项目的一个重复文本过滤写了个工具估计这玩意以后也会用到先发到这里共享一下给大家 俺编程水平很差。。希望见谅
Imports System.IO
Imports System.Threading
Public Class Main
    Public DoMainAddress As ArrayList = New ArrayList
    Public FilePath As String
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "选择文件" Then
            If RichTextBox1.Text <> "" Then
                RichTextBox1.Text = ""
            End If
            OpenFileDialog1.Multiselect = True
            OpenFileDialog1.Filter = "所有文件|*.*"
            OpenFileDialog1.FileName = ""
            OpenFileDialog1.ShowDialog()
            FilePath = OpenFileDialog1.FileName
            If OpenFileDialog1.FileName <> "" Then
                Dim RunThread As Thread = New Thread(New ThreadStart(AddressOf ReadFile))
                RunThread.Start()
                Button1.Text = "执行"
            End If
        Else
            RichTextBox1.Text = ""
            Dim RunThread As Thread = New Thread(New ThreadStart(AddressOf ReadFileRun))
            RunThread.Start()
            Button1.Text = "选择文件"
        End If
    End Sub
    Public Sub ReadFileRun()
        Dim sr As System.IO.StreamReader = New StreamReader(FilePath, System.Text.Encoding.Default, True)
        Do While sr.Peek > -1
            Dim Tempsr As String = sr.ReadLine & vbCrLf
            If DoMainAddress.Contains(Tempsr) = False Then
                DoMainAddress.Add(Tempsr)
            End If
        Loop
        sr.Close()
        Dim wrstr As String = ""
        For i As Integer = 0 To DoMainAddress.Count - 1
            wrstr &= DoMainAddress(i).ToString
            RichTextBox1.AppendText(i & "   " & DoMainAddress(i).ToString)
        Next
        Dim FileName1 As String = "\Done.txt"
        If File.Exists(Application.StartupPath & "\Done.txt") = True Then
            If MsgBox("路径:" & Application.StartupPath & FileName1 & "存在文件是否覆盖", MsgBoxStyle.YesNo Xor MsgBoxStyle.Information) = MsgBoxResult.Yes Then
                FileName1 = "\Done.txt"
            Else
                FileName1 = "\过滤完的[" & OpenFileDialog1.SafeFileName & "].txt"
            End If
        End If
        Dim wr As StreamWriter = New StreamWriter(Application.StartupPath & FileName1)
        wr.Write(wrstr)
        wr.Close()
        MsgBox("执行完毕" & vbCrLf & "生成文件路径:" & Application.StartupPath & FileName1, MsgBoxStyle.Information)
    End Sub
    Public Sub ReadFile()
        Dim sr As System.IO.StreamReader = New StreamReader(FilePath, System.Text.Encoding.Default, True)
        Do While sr.Peek > -1
            RichTextBox1.AppendText(sr.ReadLine & vbCrLf)
        Loop
    End Sub
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        CheckForIllegalCrossThreadCalls = False
    End Sub
    Private Sub 使用说明ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles 使用说明ToolStripMenuItem.Click
        MsgBox("1.按行读取比对" & vbCrLf & "2.使用首先按< 选择文件>然后< 选择文件>按钮会变成< 执行>这时候点< 执行>会在本程序目录下生成一个Done.txt或过滤完的[您选择的文件名].txt", 48, "By:MythHack")
    End Sub
    Private Sub 关于ToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles 关于ToolStripMenuItem.Click
        MsgBox("By:MythHack" & vbCrLf & "www.MythHack.com" & vbCrLf & "2012-05-22", MsgBoxStyle.Information)
    End Sub
End Class