Something like subset

see199

New member
Joined
Sep 20, 2007
Messages
1
Programming Experience
Beginner
hi, i'm newbie here... just experienced in few months in vb 2005.

i wanna ask the function, which act something like subset.

lets say i have set(10) as integer and sub(4) as integer, is there anyway to confirm that array 'sub' is the subset of array 'set'?

for example:
set has -> (1,2,3,4,5,1,2,3,4,5)
sub has -> (1,1,2,2) -> return true
sub has -> (1,1,1,1) -> return false

thanks alot
 
There's nothing specifically for that purpose. You'd just have to use a loop, e.g.
VB.NET:
'Checks whether all elements of array1 are also elements of array2.
Private Function IsSubArray(ByVal array1 As Array, ByVal array2 As Array) As Boolean
    For Each element As Object In array1
        If Array.IndexOf(array2, element) = -1 Then
            Return False
        End If
    Next element

    Return True
End Function
 
Back
Top