Sorting a multidimensional array
Peter Bogdanoff
bogdanoff at me.com
Tue Sep 30 16:33:01 EDT 2014
Dick, this works very well. Good to learn about the wrap operator.
Peter, your solution didn’t work because the htmlText contains various characters in the link tags that messes up the sorting.
Thanks both!
Peter
On Sep 26, 2014, at 3:06 AM, Dick Kriesel <dick.kriesel at mail.com> wrote:
> 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
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list