Dim groupList As New SortedList
Dim groupSublist As ArrayList
Dim lineParts As String()
Dim reader As New IO.StreamReader("file name")
While reader.Peek() <> -1
lineParts = reader.ReadLine().Split(","c)
If groupList.ContainsKey(lineParts(1)) Then
groupSublist = DirectCast(groupList(lineParts(1)), ArrayList)
Else
'Create a new list of numbers that correspond to the second number.
groupSublist = New ArrayList
groupList.Add(lineParts(1), groupSublist)
End If
'Add the last number to the list that corresponds to the second number.
groupSublist.Add(lineParts(2))
End While
Dim tempStr As New System.Text.StringBuilder
'Create the output string.
For Each groupNumber As String In groupList.GetKeyList()
If tempStr.Length > 0 Then
tempStr.Append(Environment.NewLine)
End If
groupSublist = DirectCast(groupList(groupNumber), ArrayList)
tempStr.Append(groupSublist.Count)
tempStr.Append(") ")
tempStr.Append(groupNumber)
tempStr.Append(",")
tempStr.Append(groupSublist(0))
Next
MessageBox.Show(tempStr.ToString())