Good morning everyone.
I have a list. Say [ABC, CAA, CXZ]
With the contains function I can see that the list, in one of its item, contains a certain string, say "X"
Now, I would like to extract the whole item or element which matched the search, say "CXZ.
So I guess I have to obtain the index (which, in my example, would be 2, being the third item) of the element and then use the function getElement.
How do I retrieve that?
Thank you.
retrievind index number of a certain element into a list
Moderator: Martin
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: retrievind index number of a certain element into a list
Usual loop should be enough.
Code: Select all
match = "";
s = "X"; //search string
list = newList("ABC", "CAA", "CXZ");
for(i in list)
{
if(contains(i, s))
{
match = i;
break;
}
}
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
- tsolignani
- Posts: 187
- Joined: 12 Jan 2019 11:53
- Location: Vignola, Mo, Italy
- Contact:
Re: retrievind index number of a certain element into a list
It works like a charm!
I kept it as an example for future analogue needs.
Thank you so much.
I kept it as an example for future analogue needs.
Thank you so much.