Check if element exist in array


#1

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.


#2

@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


#3

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?


#4

@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


#5

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


#6

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


#7

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


#8

Hi @Manjuts90,

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

Regards,
Arivu


#9

@arivu96 i am not getting that option in uipath