Page 1 of 1

retrievind index number of a certain element into a list

Posted: 03 Mar 2020 10:39
by tsolignani
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.

Re: retrievind index number of a certain element into a list

Posted: 03 Mar 2020 11:00
by Desmanto
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;
  }
}

Re: retrievind index number of a certain element into a list

Posted: 05 Mar 2020 15:34
by tsolignani
It works like a charm!

I kept it as an example for future analogue needs.

Thank you so much.