Comparing Two different size lists

walterf25

Expert
Licensed User
Longtime User
Hello, everyone i was wondering if anyone could help me out with this, i have two different lists, list1 has about 30 items in it, and list2 has about 75 items in it, what i need to do is compare the items from list1 and if item1 is found in list2 then extract the the name of the item on list2, and so on......
hope i'm making sense! :)

thanks everyone!
Walter
 

NJDude

Expert
Licensed User
Longtime User
A very simple code that I know it will give you a clue:
B4X:
    Dim List1, List2 as List

    List1.Initialize
    List2.Initialize
    
    For I = 0 To 30
    
        List1.Add("Item " & I)
    
    Next
    
    For I = 0 To 75
    
        List2.Add("Item " & I)
        
    Next

    For I = 0 To List1.Size - 1
    
        If List2.IndexOf(List1.Get(I)) > -1 Then
        
           Msgbox("Found in position " & I, "")
           
        End If
    
    Next
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thanks

A very simple code that I know it will give you a clue:
B4X:
Thanks again NJDude, let me test this and i will let you know if it works with what i'm trying to accomplish ;)

thanks,
Walter
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
Hi not sure if this is what you are looking for, just run 1 loop inside another the outer gets an item from list1 then the inner compares it to all of the items in list2, if there is a match then do whatever action you want then the outer loop gets the next item in list1 and does the check all over again.
B4X:
Dim SearchString As String

For x = 0 To list1.Size - 1
   SearchString = list1.Get(x)
   
   For y = 0 To list2.Size - 1
      If SearchString = list2.Get(y) Then
         'do some action on the item
         list2.RemoveAt(y)   'removes the item
         'or add to a new list
         list3.Add(list2.Get(y)
      End If
   Next

Next
 
Upvote 0
Top