Get the value from an array which contains certain string

Hey everyone,

I have an array, and I have a string variable, for example:

arrray: {“cat meow”,“dog bark”,“lion roar” etc.} and the variable I have is lets say “dog”, What I need is the “dog bark” using dog.

Is there anyway I can get it? I dont know the index of the value I want so ı need the value that contains “dog”.

Thank you

Hi @jntrk

Please refer to the Screen shot of the xaml below.
1)index 0 contains the animals name.

Hi,

Can you try the following expression?

arrInStr = {"cat meow","dog bark","lion roar" }

arrResult = arrInStr.Where(Function(s) s.Contains("dog")).ToArray

Regards,

1 Like

Hi @Yoichi

I think if @jntrk need to extract the value directly he can do this modication in the code as u suggest

arrInStr = {“cat meow”,“dog bark”,“lion roar” }

arrResult = arrInStr.Where(Function(s) s.Contains(“dog”)).ToArray.ElementAt(0).ToString

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

1 Like

is there a way to do it without for each?

The way above is done without using for each

Awesome, yes I just tried it and its working, thank you all @NIVED_NAMBIAR @pravin_calvin @Yoichi

What happens if there are multiple matches? like there are more values that include “dog” ? this just returns the first one it finds?

Hi @jntrk
You can try regex pattern to match the value
Thanks

Hi @jntrk

If there are multiple matches

Then it will return the first match only as per the above code

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed::relaxed:

Or you could use @Yoichi solution which should give you array of strings containing all strings with searched value. So in this case its filtering array :wink: