Check if element exist in array

Hello,

I need to check if a certain element or value exist in a predefined array. How could this be done in a If statement?

I need to use If Statement because I have to do something based on the result.

@andnesper
use Array_Variable.Contains(“Element_Variable”) in if activity

it will return true if array contains the value other wise it will return false.

Regards,
Mahesh

1 Like

Thanks!

If i need to keep all in a for each row DataTable activity (check 2500 lines) could i then write:

Array_Variable.Contains(“Element_Variable”) = True

And then go to either Then or Else in the If Statements?

1 Like

@andnesper
You just mention this in if activity
Array_Variable.Contains(“Element_Variable”)

then add the steps what you want to do if in case it is true, and in else if it’s false.

Let us take an array of strings Array A and we want to check whether strb is present in Array A.

Then in if condition we have to mention Array A.Contains(strb).

Regards,
Mahesh

@MAHESH1 how to get index of element with using loops in an array?

Hi @Manjuts90,

For example

 string[] array = new string[6];
        array[0] = null;
        array[1] = "carrot";
        array[2] = "rat";
        array[3] = "Sample";
        array[4] = "carrot";
        array[5] = "apple";

        int index2 = Array.IndexOf(array, "banana");

If you get -1 value you value not exists in the array.
index2 -> index of the array

Regards,
Arivu

3 Likes

@arivu96 i want with out using loop and i didn’t find indexOf option for array in uipath. Do you know any method

Hi @Manjuts90,

I am able to get the index value
Array.IndexOf(arrayvariable, "yourvalue")

Regards,
Arivu

1 Like

@arivu96 i am not getting that option in uipath

Hi Mahesh,

Thanks for your answer but it doesn’t work in case sensetive mode do you have any option for this.

Regards,
Ratndeepp

@ratndeepb

You can try like this

Array_Variable.ToList.Any(Function(x) x.ToLower.ToString.Equals(Element_Variable.ToString.ToLower))

Regards,
Mahesh

Hello,
I am writing below
result.contian(PrefixArray.IndexOf(PrefixArray, “banana”))

but getting error
PrefixArray is array of multiple elements.

and trying to search after PDF Read Text activity is executed
here then in IF condition, checking with Result.condition any of Array element value…

trying to search dynamic for my problem explain in