Re: Whose-Filtering a Text List???
Re: Whose-Filtering a Text List???
- Subject: Re: Whose-Filtering a Text List???
- From: Arthur J Knapp <email@hidden>
- Date: Fri, 12 Oct 2001 10:40:34 -0400
>
Date: Wed, 10 Oct 2001 10:08:26 -0700
>
Subject: Re: Whose-Filtering a Text List???
>
From: Allen Watson <email@hidden>
>
On Wed, 10 Oct 2001 03:28:27 -0700 Chris Page <email@hidden>
>
> nigh on 2001.10.10 12:47 AM, Jim Deacutis at email@hidden wrote:
>
>> set reducedFileList to (every item in FileList whose first character is
>
>> not redoListTest) as list
>
>> --the result here is an error message like so:
>
>> --> Can't get {"Chs.", "OLs.", "Ch.", "OL."} whose character 1 * "O".
>
> If I'm reading this correctly, the problem is that you can't use "whose"
>
> with lists. Pity.
>
Right; you have to examine the items one at a time in a repeat loop, e.g.,
>
set reducedFileList to {}
>
repeat with anItem in FileList
>
If first character of anItem is not redoListTest then copy anItem to end of
>
reducedFileList
>
end repeat
There is an alternative to a straight repeat loop. The following
can be pretty fast for larger lists, though it is propably slower than
a normal repeat loop for a small 4 item list like yours.
Like most methods involving the text item delimiters, this solution
is case-sensitive:
set list_of_strings to {"Chs.", "OLs.", "Ch.", "OL."}
WhoseTextStarts(list_of_strings, "O")
--> {"OLs.", "OL."}
property kAscii001 : ASCII character 1 -- speed up repeated calls
on WhoseTextStarts(a, s) -- case-sensitive
set tid to text item delimiters
set k1 to kAscii001
set text item delimiters to k1
set a to k1 & a
set text item delimiters to k1 & s
set a to a's text items
set b to {}
set text item delimiters to k1
repeat with x from 2 to a's length
set b's end to s & a's item x's text item 1
end repeat
set text item delimiters to tid
return b
end WhoseTextStarts
set bigList to {}
repeat 400 times
set bigList's end to "abc"
set bigList's end to "def"
set bigList's end to "ghi"
end repeat
set t1 to current date
set newList to WhoseTextStarts(bigList, "de")
set t2 to current date
t2 - t1
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.zavatone.com/