Hi there,
I wonder if somebody could please help....
I have an arraylist (arrFirstArry) which I use to populate another arraylist (arrNoDuplicates) preventing any duplicates from being added. This works fine.
What I would also like my code to do is prevent adding any partial values which may exist from being added.
i.e. my array is like this
'arrFirstArray(0) = "abc"
'arrFirstArray(1) = "abc-"
'arrFirstArray(2) = "abc-123"
'arrFirstArray(3) = "abc"
'arrFirstArray(4) = "abc-"
and I want to end up with
'arrNoDuplicates(0) = "abc-123"
but I end up with
'arrNoDuplicates(0) = "abc"
'arrNoDuplicates(1) = "abc-"
'arrNoDuplicates(2) = "abc-123"
What I would like to end up with in my new array (arrNoDuplicates) is arrNoDuplicates(0)="abc-123"
I don't see how it does not work as if I reverse the first array at the beginning, it should put arrNoDuplicates(0)="abc-123" as the first entry and then the next entry it tries to place should not be added as 'abc-123' ".contains" 'abc-'.
Any help anybody can offer is much appreciated, I hope I have explained myself clearly.
I wonder if somebody could please help....
I have an arraylist (arrFirstArry) which I use to populate another arraylist (arrNoDuplicates) preventing any duplicates from being added. This works fine.
What I would also like my code to do is prevent adding any partial values which may exist from being added.
i.e. my array is like this
'arrFirstArray(0) = "abc"
'arrFirstArray(1) = "abc-"
'arrFirstArray(2) = "abc-123"
'arrFirstArray(3) = "abc"
'arrFirstArray(4) = "abc-"
and I want to end up with
'arrNoDuplicates(0) = "abc-123"
but I end up with
'arrNoDuplicates(0) = "abc"
'arrNoDuplicates(1) = "abc-"
'arrNoDuplicates(2) = "abc-123"
VB.NET:
Dim arrFirstArray As New ArrayList()
'arrFirstArray contains say.....
'arrFirstArray(0) = "abc"
'arrFirstArray(1) = "abc-"
'arrFirstArray(2) = "abc-123"
'arrFirstArray(3) = "abc"
'arrFirstArray(4) = "abc-"
arrFirstArray.Sort()
arrFirstArray.Reverse()
Dim arrNoDuplicates As New ArrayList()
For nd As Integer = 0 To arrFirstArray.Count - 1
If Not arrNoDuplicates.Contains(arrFirstArray(nd).Trim()) Then
arrNoDuplicates.Add(arrFirstArray(nd).Trim())
End If
Next
What I would like to end up with in my new array (arrNoDuplicates) is arrNoDuplicates(0)="abc-123"
I don't see how it does not work as if I reverse the first array at the beginning, it should put arrNoDuplicates(0)="abc-123" as the first entry and then the next entry it tries to place should not be added as 'abc-123' ".contains" 'abc-'.
Any help anybody can offer is much appreciated, I hope I have explained myself clearly.
Last edited: