how to count the duplicate numbers exist in a string or integer array in vb.net?
Dim a as string = \"3,2,3\"
from the above
Another option using a Dictionary:
Dim a As String = "3,2,3"
Dim counts As New Dictionary(Of String, Integer)
For Each value As String In a.Split(",")
If Not counts.ContainsKey(value) Then
counts.Add(value, 1)
Else
counts.Item(value) = counts.Item(value) + 1
End If
Next
For Each kvp As KeyValuePair(Of String, Integer) In counts
Debug.Print("Value: " & kvp.Key & ", Count: " & kvp.Value)
Next
Output:
Value: 3, Count: 2
Value: 2, Count: 1