Convert any list to a table?
Convert any list to a table?
- Subject: Convert any list to a table?
- From: Jason Bourque <email@hidden>
- Date: Tue, 18 Sep 2001 22:53:53 -0400
Ok, before I pull out any hair.
--So how do you create a false table with tabs from a list and
--not have an extra character at the end. Plus handle even and odd lists?
--And handle any number of columns.
--Below is my code that works for a 2 column table.
--Thanks
--Jason Bourque
on createFalseTable(anyList, columnsNeeded)
set anyListCount to count of anyList
set rowsNeeded to (anyListCount div columnsNeeded) + (anyListCount mod
columnsNeeded)
set newList to {}
repeat with rowsNth from 1 to rowsNeeded
repeat with columnNth from 1 to columnsNeeded
try
item ((columnNth * rowsNeeded) - rowsNeeded + rowsNth) of
anyList
set end of newList to result
if columnNth is columnsNeeded then
set end of newList to return
else
set end of newList to tab
end if
end try
end repeat
end repeat
items 1 thru -2 of newList as string
end createFalseTable
set anyList to {"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh"}
my createFalseTable(anyList, 2)
(*
returns
"aaa eee
bbb fff
ccc ggg
ddd hhh"
*)
my createFalseTable(anyList, 3)
(*
returns
"aaa eee bbb fff ccc ggg ddd hhh"
but should return
returns
"aaa ddd ggg
bbb eee hhh
ccc fff"
*)