我剛纔看到這一點,我嘗試下面的代碼;它工作正常,我使用CheckedListBox來查看結果。 有2個arraylist使用。 'Darray'擁有重複字符串的原始列表。然後,「FinArray」轉儲不重複的字符串,然後在列表框中顯示「FinArray」內容:
Sub CleanDupes()
' Clear listbox
CheckedListBox1.Items.Clear()
' Create Final Array for non-duped data
Dim FinArray As New ArrayList
Dim InitFinarray, DarrayN, FinArrayN As String
' Add first record from original array into new array
FinArray.Add(Darray.Item(0))
InitFinarray = FinArray.Item(0)
CheckedListBox1.Items.Add("Select/Unselect All")
CheckedListBox1.Items.Add(InitFinarray)
' Loop into Orig Array and compare each record with strings in new array,
' if exist in new array, then skip, else add it
For n As Integer = 0 To Darray.Count - 1
DarrayN = Darray.Item(n)
For n2 As Integer = 0 To FinArray.Count - 1
If FinArray.Contains(DarrayN) Then
Else
FinArray.Add(DarrayN)
FinArray.Sort(1, FinArray.Count - 1, Nothing)
End If
Next
Next
'Display New Non-Duped Array in listbox
For n3 As Integer = 1 To FinArray.Count - 1
CheckedListBox1.Items.Add(FinArray(n3))
Next
End Sub
我不會永遠使用ArrayList(好吧,也許會有一些奇怪的情況,我將)。在這種情況下最好使用List(Of String)。 – Neverbirth 2011-05-31 09:39:15
不幸的是,有時候我們會堅持支持遺留代碼,即.Net 1.1。 – Roman 2013-08-08 19:59:53