Re: Get position of item in list
Re: Get position of item in list
- Subject: Re: Get position of item in list
- From: Nigel Garvey <email@hidden>
- Date: Wed, 25 Jun 2003 23:23:12 +0100
Richard Morton wrote on Wed, 25 Jun 2003 16:33:27 +1000:
>
Kai may be aware of this already, but seeing as it's speed we're
>
considering, it's perhaps worth noting that assigning multiple values
>
in one statement:
>
Is slower than doing them separately:
>
to getPosition of i from l
>
if i is not in l then return 0
>
set n to 0
>
set o to {}
>
set t to text item delimiters
>
set text item delimiters to d & d
>
set l to d & l & d
>
set text item delimiters to d & i & d
>
set l to l's text items 1 thru -2
>
set text item delimiters to d & d
>
repeat with i in l
>
set i to i as string
>
if i is not "" then set n to n + 1
>
tell n + (count i's text items)
>
set n to it
>
set o's end to it
>
end tell
>
end repeat
>
set text item delimiters to t
>
return o
>
end getPosition
Don't forget too that counting is faster than string comparisons:
property d : ASCII character 1
to getPosition of i from l
set n to 0
set o to {}
set t to text item delimiters
set text item delimiters to d & d
set l to d & l & d
set text item delimiters to d & i & d
if (count l's text items) = 1 then -- count: 1 text item = not in list
set o to 0
else
set l to l's text items 1 thru -2
set text item delimiters to d & d
repeat with i in l
set i to i as string
if (count i) > 0 then set n to n + 1 -- count: > 0 = not ""
set n to n + (count i's text items)
set o's end to n
end repeat
end if
set text item delimiters to t
return o
end getPosition
NG
_______________________________________________
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.