Re: Determining item number matching "x" in a list
Re: Determining item number matching "x" in a list
- Subject: Re: Determining item number matching "x" in a list
- From: Paul Skinner <email@hidden>
- Date: Wed, 12 Mar 2003 09:39:34 -0500
A less fuzzy headed version...
ItemIndex({searchTerm:"c", inputList:{"c", "c", "c", "a", "a", "b",
"c", "c", "c", "c", "etc", "c", "c"}})
-->{1, 5, 7, 9, 10}
on ItemIndex(parameters)
set {pd, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, ""}
set {rareDelimiter, thisIndex, indices, currentListPosition} to {ASCII
character 240, 0, {}, 0}
set searchTerm to rareDelimiter & searchTerm of parameters &
rareDelimiter
set inputList to inputList of parameters
set AppleScript's text item delimiters to rareDelimiter & rareDelimiter
set inputList to ({rareDelimiter} & inputList & {rareDelimiter}) as
text
set AppleScript's text item delimiters to searchTerm
set inputList to (every text item of inputList as list)
set occurances to (length of inputList) - 1
set AppleScript's text item delimiters to {rareDelimiter &
rareDelimiter}
repeat with i from 1 to occurances
set thisListChunk to item i of inputList
try
set chunkLength to (length of every text item of ((text 2 thru -2 of
thisListChunk)))
on error
if thisListChunk is "" then set chunkLength to 0
end try
if thisListChunk is rareDelimiter & rareDelimiter then set
chunkLength to 1
set the end of indices to currentListPosition + chunkLength
set currentListPosition to currentListPosition + chunkLength + 1
end repeat
set AppleScript's text item delimiters to pd
return indices
end ItemIndex
_______________________________________________
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.