tags:

views:

85

answers:

1

Dear All,

How i can find multiple occurence in given string in vb.net

For e.g my string is two times : 1234567

1234567,Desction,1.32

1234555,Desction,2.30

1234556,Desction,2.30

1234557,Desction,2.30

1234567,Desction,1.32

I want to put this two rows into a Dropdown Menu which is on my Form

Its Urgent

Thanks in Advance

A: 

Lets say that what you need is to find all duplicates in a list of strings, Using a bit of linq you can try

Dim list As New List(Of String)() 
list.Add("1234567,Desction,1.32") 
list.Add("1234555,Desction,2.30") 
list.Add("1234556,Desction,2.30") 
list.Add("1234557,Desction,2.30") 
list.Add("1234567,Desction,1.32") 
Dim duplicates = From s In list _ 
    Group s By sIntog _ 
    Where g.Count() > 1 _ 
    Select g 

For Each s In duplicates 
    Dim duplicate As String = s.Key 
Next

Then in the For Each, you can populate the DropDown Items from the strings.

Well, in that case you can try something like

Dim duplicates As New List(Of String)() 

For iString As Integer = 1 To list.Count - 1 
    If Not duplicates.Contains(list(iString - 1)) Then 
        For iCompare As Integer = iString To list.Count - 1 
            If list(iString - 1) = list(iCompare) Then 
                duplicates.Add(list(iString - 1)) 
                Exit For 
            End If 
        Next 
    End If 
Next
astander
Actually i am using VB.Net 2003 ans this code is not working on that.How to convert into .Net 2003 of your code and try.Kindly help on this.
imtyaz