Re: list of lists as arrays
Re: list of lists as arrays
- Subject: Re: list of lists as arrays
- From: has <email@hidden>
- Date: Wed, 3 Apr 2002 17:32:53 +0100
Paul Berkowitz wrote:
>
Hmm. i usually read the whole text in at once, then use AppleScript's text
>
item delimiters {return} and {tab} as needed to get the separate items. That
>
should be much faster than reading a line at a time since tids don't require
>
a scripting addition (read) call.
Yeah, something like the following tends to do the job quite nicely and can
be further customised/optimised if you like:
======================================================================
on convertTabDelimitedTextToArray(theText)
set oldTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set textLines to theText's text items
set AppleScript's text item delimiters to tab
set newArray to {}
repeat with eachLine in textLines
set newArray's end to eachLine's text items
end repeat
set AppleScript's text item delimiters to oldTID
newArray
end convertTabDelimitedTextToArray
-------
--TEST
set tabDelimitedText to "one 2 foo
three 4 bar"
convertTabDelimitedTextToArray(tabDelimitedText)
======================================================================
[Moral: AppleScript is not BASIC.;]
has
p.s. If you're interested, I've a dinky little doodad called tableLib due
for release Real Soon Now [just gotta finish documenting it]. It has nice
sorting and filtering features for working with data, and import/export
options for tab-delimited text.
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.