If string contains certain elements then xxx

Hello

I have a string in a variable and its content is fixed:

var 1 = A, B, C, D, E, F, G, H

Then I have another variable that contains string with elements, it should always be the same as variable 1 so:

var 2 = A, B, C, D, E, F, G, H

What I need is a way to verify if my variable 2 is the same as my variable 1 and if not then I will need to log what is the difference. So for example my log would be:

In the case above:

missing elements: none

In the following case:

var 1 =

A, B, C, D, E, F, G, H, I, J

var 2 = B, C, A, F, E, G, (H, I, and J are missing here)

the log would need to look like:

missing elements: H, I, J

How should I approach it?

Hi @chowus

Assign var1 = "A, B, C, D, E, F, G, H"
Assign var2 = "B, C, A, F, E, G"

Assign array1 = var1.Split(","c).Select(Function(s) s.Trim()).ToArray()
Assign array2 = var2.Split(","c).Select(Function(s) s.Trim()).ToArray()
Assign missingElements = array1.Except(array2).ToArray()

If missingElements.Length = 0
  Log Message: "Missing elements: none"
Else
  Log Message: "Missing elements: " + String.Join(", ", missingElements)

Hope it helps!!

so what if my string is not divided by “,” but different charracter? is this where I change it?

Assign array1 = var1.Split(","c).Select(Function(s) s.Trim()).ToArray()

@chowus You can split with any seprator but it should be fixed.

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