Hey folks,
I’ve been wrecking my brain trying to figure this out; searching high and low here on Macscripter and through the Language Guide, etc.: Is it possible to remove items from a list (of about 200 items) using only a partial string match?
So for example I’ve got a large list of different packages from an Android device; a list that looks like this:
{com.htc.blah.blah, com.google.googledevice, com.android.bliggyblah, com.random.companyapp}
I want to remove certain items from that list but keep others; anything containing “com.htc.”, or “com.google.” needs to go, and anything without it should stay. I can’t do exact string matches since there’s an infinitesimal amount of possibilities that any of the “com.whatever.” could be attached to. Here’s what I’ve tried so far as a proof of concept:
set itemsToDelete to {"com.htc."}
set cleanList to {}
repeat with i from 1 to count packageList_
if {packageList_'s item i} does not contain itemsToDelete then set cleanList's end to packageList_'s item i
end repeat
packageList_ contains the list of 200 items
cleanList is where I’m trying to send all the good stuff so I can use it later
itemsToDelete - fairly self explanatory. ideally this will have multiple items in it as well to search for and remove.
As you can see above I have “com.htc.” in there hoping it will remove any of those items in the list that contain that string. But this does not work; the statement always returns false. If I was to replace “com.htc.” with something specific that is within packageList_ (like “com.google.android.talk”) it seems to work - but only for that single item. If I add a second item to the list it will seem to skip it.
Currently I’m stumped, since by all my testing this works:
set myTestList to {1, 2, 3, 4, 5, 6, 7, 8}
set itemsToDelete to {4, 5, 6}
set goodList to {}
repeat with i from 1 to count myTestList
if {myTestList's item i} is not in itemsToDelete then set goodList's end to myTestList's item i
end repeat
goodList
The Language Guide seems to indicate that you can use / but that doesn’t seem to work either, and the only other reliable source I was able to find (http://www.acm.uiuc.edu/iCal/workshops/applescript/1999/introduction/conditions.html - indicates that its not possible to get a partial match inside a list. But that’s from ages ago, and it doesn’t give any alternatives.
Is it possible to do this? Am I missing something stupid?
Browser: Safari 535.11
Operating System: Mac OS X (10.7)