Checking if elements of list are contained in the main list

Hello

I have a string, variable 1 that looks like:

A, B, C, D, E, F, G

then I have my second string variable 2 that looks like:

F, E, D

What I need is:

I use variable 1 as a kind of a list and if all elements of variable 2 are contained in the list (variable 2 is always fixed) then its fine but I need to log an error when they are not so for example:

1st example:

variable 1 = A, B, C, D, E, F, G
variable 2 = F, E, D

output: none (as all elements of variable 2 are contained in variable 1.

2nd example:

variable 1 = A, B, C, D, F, G (E is missing)
variable 2 = F, E, D

output: E is missing from the list

3rd example:

variable 1 = A, C, F, G
variable 2 = B, E, G

output: B, and E are missing from the list

How would you approach this?

Hi,

How about the following sample?

arr1=variable1.Split({","c," "c},StringSplitOptions.RemoveEmptyEntries)
arr2=variable2.Split({","c," "c},StringSplitOptions.RemoveEmptyEntries)

then

arr2.Except(arr1).ToArray

Sample20230919-4L.zip (3.1 KB)

Regards,

HI @anon40731888 you can go with this for your output

1st example
image

2nd example
image

3rd example
image

Hi @anon40731888
Try this:

Assign variable1List = variable1.Split({","}, StringSplitOptions.RemoveEmptyEntries).Select(Function(x) x.Trim()).ToList()
Assign variable2List = variable2.Split({","}, StringSplitOptions.RemoveEmptyEntries).Select(Function(x) x.Trim()).ToList()

Assign missingElements = New List(Of String)

For Each element In variable2List
    If Not variable1List.Contains(element) Then
        missingElements.Add(element)
    End If
Next

If missingElements.Count = 0
    Log Message: "None (as all elements of variable 2 are contained in variable 1)"
Else
    Log Message: String.Join(", ", missingElements) & " is/are missing from the list"
End If

Hope it helps

Hello, I can’t open it I have studioX:(

Hi,

Can you try the following sample?

NewBlankTask20230919-1.zip (49.9 KB)

Regards,