Compare two arrays, remove partial


have a question. So I have to compare between two array’s and remove a string that will always return a partial. EG:

Array1: John Smith, Jane Doe, Jerry Jacob
Array2: John S, Jane D, Jerry J

If Array1 contains array2, remove that entry.

I was attempting to use a Linq expression: Array1.Except(Array2).ToArray but this doesn’t work as it looks for an exact match. Thought maybe wild cards would work as well but no luck there either.

I was thinking of using something like Array.Exists but was unsure if that would work for this. Anyone have a solution for this?

if the second array values can always contain part of the values on the first, then you could just test each value inside a loop, just you cant remove items from arrays, then easier to create a list instead.

Thank you for the response!

I have to compare names and one source gives full name, second source gives First name plus last initial. So it’ll always contain part of the values.

Apologies if it’s an ignorant question but how would I go about testing through a loop? And I would need to create a new array removing what was found correct? Don’t want to use list because it’ll have to “remember” it’s position at a later point in the automation.

lists will keep their items index the same way and will give you extended features to help you find the items using contains…

Dim names = (From name in ListOfNames where name.StartsWith("John S")).ToList
If Not names.Any() Then
End If
1 Like

I was not aware of that! Thank you for the explanation and the example!! I greatly appreciate your assistance.

I’ll give this a shot and mark the answer as soon as I confirm.

1 Like

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