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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the format of the strings in StringBuilder object?
ASKER
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:\t emp\TSMemb ersDayOld. txt")
For Each line In strOldList
arrTSList.AppendLine(line)
Next
End Sub
Public Sub TSRestrictedDayOld()
'read day old file
arrTSListOld.Clear()
Dim strOldList() As String
strOldList = IO.File.ReadAllLines("c:\t
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.t xt". 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:\t emp\TSMemb ersDayOld. 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).To Array()
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:\t
' 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).To
ASKER
Great ChloesDad! I will give that a shot and thanks for the tips!
FernandoSoto, the list looks like:
userid1
userid2
userid3
FernandoSoto, the list looks like:
userid1
userid2
userid3
Did this solve your problem?
ASKER
got both solutions working...thanks so much!
ASKER
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?