I am having some trouble with de-duplicating an array. I used a method that I picked up from this forum from some years ago (Xojo Array: Remove duplicate elements?), and it is not removing all duplicates.
This is the method, which takes as its parameter a previously-sorted array (I’ve checked the sorting step and this works fine):
for i as Integer = 0 to theArray.Ubound-1 // compare the current member with the next member // if they are the same, remove the current member if theArray(i) = theArray(i + 1) then theArray.Remove(i) end if next
When I check the results most of the duplicates are still there. I think it may be to do with the counting of array members. The method uses an incrementing integer i, and if I remove the i-th member, does the next member get assigned i as its position in the array? If not, does that mean that the counter “skips over” the next member?
Also, why doesn’t it give an error at the Ubound end of the array? If I have made the array smaller by removing members, the value of Ubound(theArray) will be wrong, won’t it?
All rather confusing. Can someone set me straight on this please?