Sorting a multidimensional array
Dick Kriesel
dick.kriesel at mail.com
Fri Sep 26 06:06:10 EDT 2014
On Sep 25, 2014, at 9:24 PM, Peter Bogdanoff <bogdanoff at me.com> wrote:
> My first foray into arrays
Hi, Peter.
For this foray, you could use a one-dimensional array, containing the three lines of html text for each plain text key:
command sortGroupsOfLines
local tText, tLineNumber, tGroup, tKey, tArray, tKeys, tSortedGroups
put the text of fld 1 into tText
split tText by cr and null
repeat for each line tLine in the HTMLtext of fld 1
add 1 to tLineNumber
switch tLineNumber wrap 3
case 1
put tText[ tLineNumber ] into tKey
put tLine & cr into tGroup
break
case 2
put tLine & cr after tGroup
break
case 3
put tGroup & tLine & cr into tArray[ tKey ]
end switch
end repeat
put the keys of tArray into tKeys
sort tKeys
repeat for each line tKey in tKeys
put tArray[ tKey ] after tSortedGroups
end repeat
set the HTMLText of fld 2 to tSortedGroups
end sortGroupsOfLines
Because this approach has only three references to objects, it's faster.
How's that, Peter?
-- Dick
More information about the use-livecode
mailing list