Sorting a list of strings
From Director Online Wiki
Problem
- Windows: Director MX 2004 and earlier
- Mac: ???
Sorting a list of strings with Lingo is a bit problematic as the following example demonstrates:
-- Lingo-Syntax myList = ["bbb","-ccc","aaa"] myList.sort() put myList -- ["aaa", "bbb", "-ccc"]
The result is wrong.
The expected result would have been ["-ccc", "aaa", "bbb"],
because charToNum("-") < charToNum("a")
Solution
Create a Flash Array Object from the list of strings and sort it:
-- Lingo-Syntax myList = ["bbb","-ccc","aaa"] myList = convert(#list, convert(#flashObjectArray, myList).sort()) put myList -- ["-ccc", "aaa", "bbb"]