Sorting a multidimensional array

Peter Bogdanoff bogdanoff at me.com
Fri Sep 26 00:24:38 EDT 2014


My first foray into arrays:

I want to sort a 2D array by one of the keys.

The data consists of several 2-line groups that are in a field. The lines contain styled and linked characters that I want to retain after sorting:

peaches
pears

apples
oranges

plums
grapes

I want to sort the data by line 1 of each 2-line group, then display the sorted data as styled text.

I build an array:

repeat with x = 1 to (the number of lines of field “tField" / 3)
	put line 1 of field “tField" into tMultiArray[x][1]
	put the htmlText of line 1 of field “tField" into tMultiArray[x][2]
	put the htmlText of line 2 of field “tField" into tMultiArray[x][3]
	delete line 1 to 3 of field “tField"
end repeat

How do I sort this array by line 1 of the plain text of each group?

Then, how do I extract the data from the array—I need the 2nd & 3rd values only (the htmlText) to display again in the field (set the htmlText of line x of field “tField” to…?)?

Is this the best method to sort this kind of data? The data comes as search results using Scott McDonald’s RunRev Planet Search tool, so I have to work with what the tool gives me.

I do appreciate any help!

Peter Bogdanoff
UCLA



More information about the use-livecode mailing list