jntrk
(jntrk)
March 19, 2021, 8:17am
1
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.
Yoichi
(Yoichi)
March 19, 2021, 8:34am
3
Hi,
Can you try the following expression?
arrInStr = {"cat meow","dog bark","lion roar" }
arrResult = arrInStr.Where(Function(s) s.Contains("dog")).ToArray
Regards,
2 Likes
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
Happy Automation
3 Likes
jntrk
(jntrk)
March 19, 2021, 10:16am
5
is there a way to do it without for each?
The way above is done without using for each
jntrk
(jntrk)
March 19, 2021, 10:31am
7
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
Happy Automation
Yameso
(Jakub Swiderski)
March 19, 2021, 4:32pm
10
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