3
나는 각 줄마다 한 단어 씩 약 45,000 단어의 텍스트 파일을 가지고 있습니다. 이 단어의 수천은 10 번 이상 나타납니다. 반복되는 단어가없는 새 파일을 만들고 싶습니다. 스트림 리더를 사용했지만 파일을 한 번만 읽습니다. 반복되는 단어를 제거하려면 어떻게해야합니까? 도와주세요. 감사합니다 내 코드는 당신이를 위해 LINQ의 Distinct()
방법을 사용할 수 있습니다이텍스트 파일에서 반복 단어 제거
Try
File.OpenText(TextBox1.Text)
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Dim line As String = String.Empty
Dim OldLine As String = String.Empty
Dim sr = File.OpenText(TextBox1.Text)
line = sr.ReadLine
OldLine = line
Do While sr.Peek <> -1
Application.DoEvents()
line = sr.ReadLine
If OldLine <> line Then
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Splitted File without Repeats.txt", line & vbCrLf, True)
End If
OldLine = line
Loop
sr.Close()
System.Diagnostics.Process.Start(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Splitted File without Repeats.txt")
MsgBox("Loop terminated. Stream Reader Closed." & vbCrLf)
물론 사랑하는 라키 티치를. 너는 그것을 desreve. – gulmaily