Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

compare 2 arrays

I have 2 arrays that contain a bunch of user ids called arrA and arrB.  How can I find the user id's in arrB that do not exsist in arrA with visual basic .net?
ASKER CERTIFIED SOLUTION
Avatar of ChloesDad
ChloesDad
Flag of United Kingdom of Great Britain and Northern Ireland 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
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America 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
Avatar of chadmanvb
chadmanvb

ASKER

Sorry for the long delay, but they both look like great solutions.  I did mention an array, but really it's a stringbuilder I created.

 Dim arrTSList As New StringBuilder
 Dim arrTSListOld As New StringBuilder

I'm not sure how to convert between the stringbuild and array to get this working.  Could I do the same thing with the stringbuilder?
What is the format of the strings in StringBuilder object?
im not sure how to tell.  Heres how I build it.

 Public Sub TSRestrictedDayOld()
        'read day old file
        arrTSListOld.Clear()
        Dim strOldList() As String
        strOldList = IO.File.ReadAllLines("c:\temp\TSMembersDayOld.txt")
        For Each line In strOldList
            arrTSList.AppendLine(line)
        Next
    End Sub
In order to be able to help you I need to know what the data looks like in the file "c:\temp\TSMembersDayOld.txt". Can you post the file or attach the file here?
The problem with using a string builder is that you then have to delimit the string to get back to an array for at least one of the string builders. And you definitely should not be suffixing a stringbuilder with arr as everyone will assume that its an array, which it isn't. In fact use of Hungarian notation is now considered bad practice.

You already have the data as a string array, so you can work with that using FernandoSoto's method as its just one line. :)

         ' copy the last newlist to OldList for comparing
        Array.Copy(NewList, OldList, NewList.Length)

        NewList = IO.File.ReadAllLines("c:\temp\TSMembersDayOld.txt")
        ' here NewList is already a string array, so we dont need to do anything with it

' donotExistInOld is an array of strings
Dim donotExistInOld = NewList.Except(OldList).ToArray()
Great ChloesDad!  I will give that a shot and thanks for the tips!

FernandoSoto, the list looks like:
userid1
userid2
userid3
Did this solve your problem?
got both solutions working...thanks so much!