How can I delete the same thing with Array?

How can I delete the same thing with Array?

Text = Array( “Banana”, “Apple”,”Orange”, “Banana”,”Orange”)
===> Array(“Banana”,“Apple", “Orange”)

sort the array

MyArray.sort

and then loop through it backwards

for x = upperlimit downto 1 if array(x) = array(x-1) then array.remove(x) end if next

or Use a dictionary

dim d as new dictionary d.value ("Banana") = "" d.value ("Apple") = "" d.value ("Banana") = ""
the dictionary now only contains one each Banana and Apple

Or, put the array into a database table, and select from it:

myRS = mydb.select ("select distinct fruitname from fruittable")

[quote=399913:@Jeff Tullin]sort the array

Thank you

I do not want to sort it.
I thought about using a dictionary, but it is sorted.

Use a dictionary … working backwards , if the dictionary has seen this value before, remove it
Otherwise add the value to the dictionary
First time it sees banana, it adds to the dictionary
second time, it deletes a value from the array.

[quote]dim d as new dictionary
for x as integer = arrayupperindex downto 0
if d.haskey(array(x) then
array.remove(x)
else
d.value(array(x)) = “”
end if
next[/quote]

If you are concerned about the order of the array, I’m unclear why you also want to remove an item from it.

[code]Dim Fruit() As String = Split(“Orange,Apple,Banana,Orange,Banana”, “,”)

For i As Integer = Fruit.Ubound DownTo 0
If Fruit.IndexOf(Fruit(i)) < i Then
Fruit.Remove(i)
End If
Next
[/code]

No sorting required see http://developer.xojo.com/arrays$IndexOf

[quote=399920:@Wayne Golding][code]Dim Fruit() As String = Split(“Orange,Apple,Banana,Orange,Banana”, “,”)

For i As Integer = Fruit.Ubound DownTo 0
If Fruit.IndexOf(Fruit(i)) < i Then
Fruit.Remove(i)
End If
Next
[/code]

No sorting required see http://developer.xojo.com/arrays$IndexOf[/quote]

Thank you for giving me good advice.