Remove Duplicates

Hello guys i want to remove the duplicates from a list box in VB .net

i have list of items.

Required.

Split the listbox
match the split part with all the items in list box
if there are any other items like that
REMOVE those items
and repeat that for all the items in listbox.
rosa545Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

systanCommented:
0
rosa545Author Commented:
may something like this???? as the input is


James=Accounts&Register
Malisa=Support
Ben=Transporting
James=Accounts&Register

so this is sample data so all i need is to split it with "=" and take 0 of array and remove the duplicates now it would be clear but the method should be splitting and using array.

        For Each item In ListBox1.Items


            Dim p As String = ListBox1.Text
            Dim p1() As String

            p1 = p.Split("=")


            If ListBox1.Text.Contains(p1(0)) Then



                ListBox1.Items.Remove(ListBox1.Text)

            End If


        Next

Open in new window

0
rosa545Author Commented:
is there no way to get that done?
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Mel-Leo RosalCommented:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.Add("asd") '
        ListBox1.Items.Add("222") '
        ListBox1.Items.Add("asd")
        ListBox1.Items.Add("ddd") '
        ListBox1.Items.Add("xxx") '
        ListBox1.Items.Add("ddd")
        ListBox1.Items.Add("222")
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ListBox1.Sorted = True

        Dim x As Integer = 0
        Dim intCount As Integer = ListBox1.Items.Count - 1
        Dim strTemp As String = vbNullString

        While x < intCount
            If ListBox1.Items(x) = strTemp Then
                MsgBox("removing  " & ListBox1.Items(x))

                ListBox1.Items.RemoveAt(x)

                intCount = intCount - 1
            Else
                strTemp = ListBox1.Items(x)

                x = x + 1
            End If
        End While
       
    End Sub

Open in new window


How about this. Sort it, then check if the previous string is the same, if it is then remove. xD
0
rosa545Author Commented:
well there is no splitting done by =

i need to have a splitting function too
0
Mel-Leo RosalCommented:
   Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.Add("James=Accounts&Register") '
        ListBox1.Items.Add("Malisa=Support") '
        ListBox1.Items.Add("Ben=Transporting")
        ListBox1.Items.Add("James=Accounts&Register") '
        ListBox1.Items.Add("Luffy=Accounts&Register") '
        ListBox1.Items.Add("Jim=Accounts&Register") '
        ListBox1.Items.Add("Luffy=Support") '
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ListBox1.Sorted = True

        Dim x As Integer = 0
        Dim intCount As Integer = ListBox1.Items.Count - 1
        Dim strTemp As String = vbNullString
        Dim strList() As String

        For x = 0 To intCount
            strList = ListBox1.Items(x).ToString.Split("=")
            ListBox1.Items.RemoveAt(x)
            ListBox1.Items.Add(strList(0))
        Next

        x = 0
        While x < intCount
            If ListBox1.Items(x) = strTemp Then
                MsgBox("removing  " & ListBox1.Items(x))

                ListBox1.Items.RemoveAt(x)

                intCount = intCount - 1
            Else
                strTemp = ListBox1.Items(x)

                x = x + 1
            End If
        End While

    End Sub

Open in new window


Try this. I dunno if this is what you need.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.