I’m trying to filter a list and get rid of the empty “” items. for some reason when I do a comparision appescript is treating the “” item as if it doesn’t exist. What am I missing ?
thanks
set x to {“3”, “”, “1%”, “5%”, “”, “Don’t try this at home”}
set new_list to {}
repeat with i in x
if i is not “” then
display dialog i & " is not equal to """
set end of new_list to i
else
display dialog i & “is equal "" skipping.”
end if
end repeat
Hi,
this is a common mistake.
If you perform a comparison in an iteration using the repeat with anItem in aList form,
the index variable is a reference to the list item, not the value. The comparison is actually
if item 2 of {"3", "", "1%", "5%", "", "Don't try this at home"} is not ""
To compare values and to change a value in the list you have to dereference the list
.
if contents of i is not "" then
.
Perhaps something like this
set myList to {"alpha", "", "", "Gamma", "delta"}
set mycount to 0
repeat until (count of myList) = mycount
set mycount to count of myList
set AppleScript's text item delimiters to {"."}
set myList to (myList as string)
set AppleScript's text item delimiters to {".."}
set myList to text items of myList
set AppleScript's text item delimiters to {"."}
set myList to text items of (myList as string)
end repeat