The function sorts an item string in ascending order and returns the sorted string or a specific number of items. If the items of the item string contain sub-items, you may specify a sub-item as the sorting key.
Syntax
ListSort(cValueExpr,nItemsReturned,cSeparator,nSortSubItem,cSubItemSeparator)
Or
ListSort(cValueExpr,nItemsReturned,cSeparator,cSortExpr,cSubItemSeparator)
Argument |
Description |
Example |
cValueExpr |
The item string or an expression returning an item string |
'12:45/6:00/9:40' |
nItemsReturned |
Return how many numbers of items. Default to all items. Default to all items. |
3 |
cSeparator |
Item separator, can be more than 1 character (default to ',') |
'/' |
nSortSubItem |
An ordinal number specifying which sub-item to be sorted. If omitted, the whole item will be sorted |
2 |
cSortExpr |
Use the value returned by ListCol( ) and ListColVal( ) to determine the order. Please see the examples below for details |
'ListColVal(1)+ListColVal(2) |
cSubItemSeparator |
Sub-item separator, can be more than 1 character (default to '-') |
':' |
Returns
Character
Example
ListSort('Orange,Apple,Grape,Pear')
Returns 'Apple,Grape,Orange,Pear'.
ListSort('12:45/6:00/9:40',3,'/',2,':')
Returns '6:00/9:40/12:45'. The 2nd sub-items of the item string are '45', '00', and '40' respectively. After sorting on the 2nd sub-items, the item string becomes '6:00/9:40/12:45'.
ListSort('5-4,23-15,3-26',1,,2)
Returns '23-15,5-4,3-26'. The 2nd sub-items of the item string are '4', '15' and '26' respectively. (Please note that when comparing strings, '4' is greater than '15' since '4' > '1'. When comparing numbers, 4 is smaller 15) Therefore, after sorting, the item string becomes '23-15,5-4,3-26'.
ListSort('5-4,6-1,2-6',1,,'ListColVal(1)+ListColVal(2)')
Returns '6-1,2-6,5-4'. The argument 'ListColVal(1)+ListColVal(2)' asks the system to sort on the numeric sum of the 1st and 2nd sub-items:
Item |
ListColVal(1)+ListColVal(2) |
'5-4' |
5 + 4 = 9 |
'6-1' |
6 + 1 = 7 |
'2-6' |
2 + 6 = 8 |
Since 7<8<9, after sorting the item string becomes '6-1,2-6,5-4'.
ListAscItem('5-4,6-12,2-6',1,,'ListCol(1)+ListCol(2)')
Returns '6-12,5-4,2-6'. The argument 'ListCol(1)+ListCol(2)' ask the system to sort on the concatenation of the 1st and the 2nd sub-items:
Item |
ListCol(2)+ListCol(1) |
'5-4' |
'4' + '5' = '44' |
'6-12' |
'12' + '6' = '126' |
'2-6' |
'6' + '2' = '62' |
Since '126'<'44'<'62' (note: '126'<'44' because '1'<'4'), the item string after sorting becomes '6-12,5-4,2-6'.
Page url: http://www.racematenet.com/english/help/index.html?listsort.htm