Question Compare Two StringCollections?

TBossAZ

Active member
Joined
Mar 31, 2009
Messages
43
Programming Experience
5-10
Greetings Everyone,

Is there a way to compare two variables that are StringCollections to find out if they both contain the same data or not?
 
Check both containers for the variable.

VB.NET:
Dim sc1 As New StringCollection
' add some stuff
Dim sc2 As New StringCollection
' add some stuff

If sc1.Contains(<var>) AndAlso sc2.Contains(<var>) Then
'do something
Else
'do something else
End If
 
Thanks for the help newguy.

What I did was fisrt compare the counts for the two StringCollections and if the counts were different, then the StringCollections were different. If the counts were the same, then I would do a second check where I loop through the first StringCollection with a For...Each loop and then see if each item from the first StringCollection was in the second collection via the Contains() method.

Thruth be told, I was hoping to find a more simple way to compare two StringCollections with some kind of Compare or EqualsTo method, but that does not seems to be the case.

If anyone has any other ideas, or would like to see the code I came up with, let me know.

Thanks!
 
Back
Top