Re: Arrays in AppleScript ?
Re: Arrays in AppleScript ?
- Subject: Re: Arrays in AppleScript ?
- From: kai <email@hidden>
- Date: Thu, 29 Dec 2005 20:35:56 +0000
On 29 Dec 2005, at 18:55, Paul Berkowitz wrote:
set mylist to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
set listInsert to "x"
set insertAfterPosition to 7
set mylist to my InsertInList(mylist, listInsert, insertAfterPosition)
--> {"a", "b", "c", "d", "e", "f", "g", "x", "h", "i", "j"}
on InsertInList(theList, listInsert, insertAfterPosition)
set end of theList to "dummy"
set listcount to count theList
repeat (listcount - insertAfterPosition - 1) times
set item listcount of theList to item (listcount - 1) of
theList
set listcount to listcount - 1
end repeat
set item (insertAfterPosition + 1) of theList to listInsert
return theList
end InsertInList
I suppose this is all a bit tongue-in-cheek, but you could also
traverse the list from the other end:
set mylist to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
set listinsert to "x"
set insertAfterPosition to 7
InsertInList(mylist, listinsert, insertAfterPosition)
mylist
--> {"a", "b", "c", "d", "e", "f", "g", "x", "h", "i", "j"}
on InsertInList(theList, listinsert, insertAfterPosition)
set beginning of theList to beginning of theList
repeat with currPosition from 2 to (insertAfterPosition)
set item (currPosition) of theList to item (currPosition + 1) of
theList
end repeat
set item (insertAfterPosition + 1) of theList to listinsert
end InsertInList
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden