The LINQ part is the '.Distinct().ToArray()'. Without LINQ you could do it like this: Code:
Dim lines As String() = IO.File.ReadAllLines("file path here")
Dim distinctLines As New HashSet(Of String)
For Each line As String In lines
distinctLines.Add(line)
Next
Array.Resize(lines, distinctLines.Count)
distinctLines.CopyTo(lines)
IO.File.WriteAllLines("file path here", lines) The generic HashSet class was added in .NET 3.5. To do the equivalent without the HashSet: Code:
Dim lines As String() = IO.File.ReadAllLines("file path here")
Dim distinctLines As New List(Of String)
For Each line As String In lines
If Not distinctLines.Contains(line) Then
distinctLines.Add(line)
End If
Next
lines = distinctLines.ToArray()
IO.File.WriteAllLines("file path here", lines)
Bookmarks