Comparing two arrays where all elements in Array 1 contain at least one element from the second

I am trying to compare two arrays.

QUESTION: Do all elements in Array 1 contain at least one element from the second array?

Array 1 {“Robert Jones”, “Harry Smith”,“John Johnson”}
Array 2 {“Jones”,“Smith”}
Array 3 {“Jones”,“Smith”,“Johnson”,“Edwards”}

I want to compare Array 1 and Array 2 to see if all of the elements in Array 1 contain at least one element from Array 2.

Answer:
When comparing Arrays 1 and 2, the answer should be FALSE since the 3rd element of Array 1 does not contain any element from Array 2.

When comparing Array 1 and 3, the answer would be TRUE

1 Like

Hi @rlwalters
Either of this could work

boolean out_result = Array1.Intersect(array2).Any()

Cheers @rlwalters

Instead kindly follow the below steps which is another method to handle this

  1. Make sure you have two array variables named Array1 and Array2
  2. Use a for each loop and pass the Array1 as input and change the type argument as string in for each loop activity and and change the variable name as item1 from item
  3. Inside thisnfor each loop use another for each loop with input as Array2 and change the type argiment as string and change the variable name as item2 from item in the inner for each loop
    –here use a if condition like this
    Item1.ToString.Contains(item2.ToString)
    If thia condition gets passed it will go to THEN part of if condition where you can mention as “Matches” in write line activity… And make sure we use a break activity next to this write line activity inside the THEN part if condition to avoid xomparing even after the match is confirmed…
    or
    It will go to ELSE part of if condition where you can mention as “Doesn’t match”
    Hope this would help you
    And sorry for the inconveniences with many comments and typo mistakes

cheers @rlwalters

2 Likes

Hi,

How would i do this but with file directories

I have 2 paths that are different but may contain the same file names. I want to just compare the file names

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.