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

6 Likes

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

4 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

2 Likes

@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

2 Likes

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

hi Mahesh1 can you please elaborate about what exactly is the meaning of entire statement? in much simpler way as that statement served my purpose. Thanks in advance.

The easiest way to do it is to convert array to list and then check via activity element exist.

  1. Create list var and set proper type.
  2. Assign - NewList = Array.tolist
  3. use element exist

2 posts were merged into an existing topic: Date time questions

Hi, Can you help me on file compare query? Please reply as soon as you see. I am confused on some similar question here.