-5

Does anyone have any sample code of how to do this? ex:

a
b
b
c
b
d

will end up as

a
b
c
b
d
user1950501
  • 19
  • 1
  • 5

1 Answers1

2

It looks to me like you want to remove repeating lines, and not simply get a list of distinct values (as demonstrated by the presence of the 'b' before the 'd' in the desired output).

If so, you can use code like this:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim lines As New List(Of String)(TextBox1.Lines)
    For i As Integer = lines.Count - 1 To 1 Step -1
        If lines(i) = lines(i - 1) Then
            lines.RemoveAt(i)
        End If
    Next
    TextBox1.Lines = lines.ToArray
End Sub
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40