## Sort List

This function sorts a list contained in a field or named variable. You can sort based on the content of each list item or by treating each list item as a sub list and sorting on a specified set of sub-list items.

If the delimiter resolves to be empty when the action is executed, a default (\~) will be assumed.

All text fields may contained any of the escape sequences described in Escape Sequences.

You may choose to sort Ascending or Descending.

There are four ways the list can be sorted:

> Compare
>   A standard case sensitive sort.
> Case Insensitive
>   Alphabetic case is ignored.
> As in Finder
>   Sorts the same way the Finder sorts items. Case insensitive and items with leading numeric values sort numerically. eg. 10 title will appear after 2 title.
> Numeric
>   Sorts based on the integer value of each list item. Note that if a list item does not have a leading integer, it is treated as zero. While As in Finder handles some integer cases it does not handle items with leading zeros properly. ie. it does not normalize leading integer values.

The following only applies if you are sorting based on the items in sub-lists.

The above options specifies the default value for each descriptor.

If the sub-list delimiter resolves to be empty when the action is executed, a ➤\, sequence is assumed.

You specify a list of sort descriptors describing how the sort is performed. The field may contain up to 10 sort descriptors. Sort descriptors may be separated by commas or spaces. A sort descriptor has the following components. (Note that sort descriptors are case insensitive).

> A or D
>   This component is optional. It allows you to override the default sort direction set in the above options. A implies Ascending and D implies Descending.
> C or I or F or N
>   This component is optional and allows you to override the sort function set in the above options. C is for Compare, I is for Case Insensitive, F is for As in Finder and N is for Numeric.
> an integer
>   This is the zero based index of the sub-list item which is the sort parameter.

Example:

- You've read a CSV file with a Read Text File statement
- Used a CSV Data to List statement to decode the data
- You've removed the header row with a Remove List Item at Index 0 statement
- You want to sort based on column 0 (ascending-case insensitive), column 3 (descending-as in Finder) and column 9 (ascending-as in Finder).

You could enter the following to sort:

> default direction: Ascending
> default function: As in Finder
> descriptors: I0 D3 9

If an invalid descriptor is found at runtime, it and all subsequent descriptors are ignored. If an invalid index is found at runtime, equality is assumed while comparing.