All,
I have two questions involving lists.
- How do I check if a list has an empty string? For e.g. the following piece of code is supposed to
just display Honda and Audi, but it displays the empty string as well.
property theList : {"", "Honda", "Audi"}
repeat with theCar in theList
if theCar is not equal to "" then
display dialog theCar
end if
end repeat
- If I know the string within a List, is there a way to fetch its index in the list?
For Eg, If I have the string “Audi”, is there a way to fetch its index(which is 3) in the list “theList”
If you got it, it would also be nice for others that you post the solution. So for other readers,
Answer 1: Variable theCar is an reference to an list item and not it’s contents. The statement should look like this.
contents of theCar is not ""
Answer 2: If you want to get the index, don’t use an iterator but a normal repeat-with-from-to loop. Like
set theList to {"", "Audi", "Honda", "BMW", "Mercedes"}
indexOfItem("bmw", theList) --returns: 4
on indexOfItem(theItem, theList)
repeat with x from 1 to count theList
if item x of theList = theItem then
return x
end if
end repeat
return null
end indexOfItem
Thanks for the reply, DJ Bazzie Wazzie
Here is how I got it to work:
Answer 1:
if theCar as string is not equal to "" then
Answer 2: followed the same approach