Re: if clauses: multiple values in one test?
Re: if clauses: multiple values in one test?
- Subject: Re: if clauses: multiple values in one test?
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 20 Sep 2003 16:35:07 -0700
On 9/20/03 3:34 PM, "Mikael Bystrvm" <email@hidden> wrote:
>
How can I shorten a long line of nearly identical tests, except for the
>
value it tests against, in an if clause?
>
Say I have
>
"if (FileName ends with "X") or (FileName ends with "Y") or (FileName
>
ends with ".Z")....... (*plus 26 more or so*)
>
then"
if {last character of fileName} is in {"X", "Y", "Z"} then
assuming you can confine it to one character, or
if ({last character of fileName} is in {"X", "Y", "Z"}) or ({text -2
thru -1 of fileName} is in {".X", ".Y", ".Z"}) or ....
which will at least be a lot shorter than 29 "or"s.
It looks as if you may also want to put the whole thing inside a
'considering case' block - or perhaps not.
>
>
Can I use an array of string values instead and have them all in only one
>
test? How can I express that in this situation?
>
Or can I at least write "with x or y or z" or similar in a simple way?
The simplest would be if you actually know all possibilities for the full
string values, and then you could do:
set allPossibleStrings to {"whazit", "whoseit", "whereit",...}
if {fileName} is in allPossibleStrings then...
But 'ends with' and 'starts with' don't lend themselves to anything except
the full sequence as you're using it.
Before we leave the topic, are you sure you shouldn't be doing this in the
Finder using its 'name extension' property (or name property) if that's what
you're actually looking for?
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.