Sorting text
LiveCode provides us with the ability to easily sort data in both ascending and descending order. In this recipe, we will sort a list of US states in ascending order.
How to do it...
Follow the steps in the recipe to sort text:
Create a new main stack in LiveCode.
Add a button to the card with the following properties:
Name:
btnSort
Label:
Sort
foregroundColor: Black
backgroundColor: White
borderWidth:
0
Add the following code to the
btnSort
button:on mouseUp local someStates put "Connecticut" into line 1 of someStates put "California" into line 2 of someStates put "Washington" into line 3 of someStates put "Florida" into line 4 of someStates put "Rhode Island" into line 5 of someStates sort lines of someStates ascending text answer someStates titled "Sorted" end mouseUp
Run the app in the mobile simulator. As illustrated in the following screenshot, the states have been properly sorted in ascending order:
How it works...
We used the sort
command to sort the lines of...