sule Member Licensed User Longtime User Mar 8, 2014 #1 Is it possible to do a faster/better way for removing dupes from listview Code: Copy Dim i As Int,j As Int For i = 0 To lstFav.Size - 1 For j = lstFav.size -1 To (i + 1) Step -1 If lstFav.GetItem(j) = lstFav.GetItem(i) Then lstFav.RemoveAt( j) End If Next Next this work flawlessly but i wonder is it better way for b4a im newbie sorry for my English
Is it possible to do a faster/better way for removing dupes from listview Code: Copy Dim i As Int,j As Int For i = 0 To lstFav.Size - 1 For j = lstFav.size -1 To (i + 1) Step -1 If lstFav.GetItem(j) = lstFav.GetItem(i) Then lstFav.RemoveAt( j) End If Next Next this work flawlessly but i wonder is it better way for b4a im newbie sorry for my English
JTmartins Active Member Licensed User Longtime User Mar 9, 2014 #2 This is me thinking very quickly... If the itens are all of the same kind, let's say strings Then you can do a List.Sort (one line of code) Afterwards, it should be possible to compare an item with the one imediatly after. (only one for..next loop) If they are equal you can eliminate the first one and move on to the next. Opps..sorry. You mentioned LISTVIEW..I thought it was a LIST. So my post is probably useless. Last edited: Mar 9, 2014 Upvote 0
This is me thinking very quickly... If the itens are all of the same kind, let's say strings Then you can do a List.Sort (one line of code) Afterwards, it should be possible to compare an item with the one imediatly after. (only one for..next loop) If they are equal you can eliminate the first one and move on to the next. Opps..sorry. You mentioned LISTVIEW..I thought it was a LIST. So my post is probably useless.
Erel B4X founder Staff member Licensed User Longtime User Mar 9, 2014 #3 Is the question about List or ListView? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Mar 9, 2014 #5 Assuming that the values are strings: Code: Copy Dim m As Map m.Initialize Dim i As Int = 0 Do While i < list.GetSize Dim item As String = list.GetItem(i) If m.ContainsKey(item) Then list.RemoveAt(i) i = i - 1 Else m.Put(item, "") End If i = i + 1 Loop Last edited: Apr 16, 2014 Upvote 0
Assuming that the values are strings: Code: Copy Dim m As Map m.Initialize Dim i As Int = 0 Do While i < list.GetSize Dim item As String = list.GetItem(i) If m.ContainsKey(item) Then list.RemoveAt(i) i = i - 1 Else m.Put(item, "") End If i = i + 1 Loop
sule Member Licensed User Longtime User Mar 10, 2014 #6 Thank you Erel it looks like this method is faster than one that I was using Upvote 0
MaCaveAVin Member Licensed User Longtime User Apr 14, 2014 #7 Is there a way to do the same but without taking care of string case in list ? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Apr 16, 2014 #8 Here: Code: Copy Dim m As Map m.Initialize Dim i As Int = 0 Do While i < list.GetSize Dim item As String = list.GetItem(i) If m.ContainsKey(item.ToLowerCase) Then list.RemoveAt(i) i = i - 1 Else m.Put(item.ToLowerCase, "") End If i = i + 1 Loop Upvote 0
Here: Code: Copy Dim m As Map m.Initialize Dim i As Int = 0 Do While i < list.GetSize Dim item As String = list.GetItem(i) If m.ContainsKey(item.ToLowerCase) Then list.RemoveAt(i) i = i - 1 Else m.Put(item.ToLowerCase, "") End If i = i + 1 Loop