Link to home
Start Free TrialLog in
Avatar of supersuny2k
supersuny2kFlag for Netherlands

asked on

Compare two arrays- Find what's missing

Background, I have a text box that is split into an array which contains usernames, these are then search and populate into a list box.

At the end of this I would like to compare the text box array and the list box results and write to another list box to say what usernames could not be found.

How would I do that?

Many Thanks

Josh
Avatar of Dabas
Dabas
Flag of Australia image

Hi supersuny2k:
> I have a text box that is split into an array which contains usernames
Not clear.
What do you mean by "split into an array"??
Maybe you can give a concrete example?

Dabas
Avatar of supersuny2k

ASKER

With the text box,

A list of Usernames are place in the multiline text box, and then I use the split function (chr13) to load this into an Array. e.g sGid = Split(txtGid.Text, Chr(13))

Hope that helps

Cheers

Josh


put them both into a stringcollection ...

pesudo code logic ..

foreach foo in textbox
     if StringCollection2.Contains foo
           its there
     else
           its not
     end if
end for
Avatar of iboutchkine
iboutchkine

Uou can loop through array and compare with the item with the same indes in the listbox

The question is how do you write to the listbox. And if you populate the list box from arrya why do you expect that something will be missing?
GregoryYoung,

Can you explain more please

Cheers

Josh
you have an array which came from the split()

you have an array which represents the ones in the listbox (ones found)

make the array of the ones in the listbox a StringCollection instead of an array and just use

for(i=0;i<SplitString.Length;i++) {
   if(ListBoxStringCollection.Contains(SplitString[i])) {
      //its there
   } else {
     //its not
   }
}

If you put up specific code I can show you more.

Greg
doh VB.NET sorry I put it in C#
Hi Greg

Here is my code for splitting the Text Box

        sGid = Split(txtGid.Text, Chr(13))
        For l = LBound(sGid) To UBound(sGid)
            sGidSearch = Replace(sGid(l), Chr(10), "")
        Next

for the List box I am reading the as Selected items, the listbox is  MultiExtended

I see what you mean, but am lost on how to make the listbox a StringCollection, to be honest, I have never used that function

Hope this helps thank you

Josh
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect Thank you