Sorts list elements according to a sort type and sort order. Returns a sorted copy of the list.
[sortType - description]
numeric: sorts numbers
text: sorts text alphabetically, taking case into account
- aabzABZ, if sort_order = "asc"
- ZBAzbaa, if sort_order = "desc"
textnocase: sorts text alphabetically, without regard to case
- aAaBbBzzZ, in an asc sort;
- ZzzBbBaAa, in a desc sort;
listSort(list, sortType [, sortOrder] [, delimiters] [, includeEmptyFields] [, localeSensitive])
or
listSort(list, callback)
→ returns string
list.listSort(sortType [, sortOrder])
numeric
text
aabzABZ
ZBAzbaa
textnocase
aAaBbBzzZ
ZzzBbBaAa
asc
asc
desc
,
false
function(element1, element2)
. Returns whether the first is less than (-1), equal to (0) or greater than (1) the second one (like the compare functions).
false
Uses the listSort() function to get the list which sorted by type text(case-sensitive)
list = "COLDFUSION,coldfusion,adobe,LucEE,RAILO";
sortList = listSort(list, "Text", "desc");
writeOutput(sortList);
Expected Result: coldfusion,adobe,RAILO,LucEE,COLDFUSION
Uses the listSort() function with delimiters to get the list which sorted by type numeric
list = "10;20;-99;46;50";
sortList = listSort(list, "Numeric", "asc", ";");
writeOutput(sortList);
Expected Result: -99;10;20;46;50
Uses the listSort() function with delimiters to get the list which sorted by type textnocase(case-insensitive)
list = "10|RED|yeLLow|-246|green|ORange";
sortList = listSort(list, "TextNoCase", "asc", "|");
writeOutput(sortList);
Expected Result: -246|10|green|ORange|RED|yeLLow
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.