ListSort

Sorts a delimited list and returns the result

Method Signature

ListSort(list=[string], sortType=[any], sortOrder=[string], delimiter=[string], includeEmptyFields=[boolean], multiCharacterDelimiter=[boolean], localeSensitive=[boolean], callback=[any])

Arguments

Argument
Type
Required
Description
Default

list

string

true

The list to sort

sortType

any

false

Options are text, numeric, or textnocase

sortOrder

string

false

Options are asc or desc

asc

delimiter

string

false

string the list delimiter

,

includeEmptyFields

boolean

false

boolean whether to include empty fields in the returned result

false

multiCharacterDelimiter

boolean

false

boolean whether the delimiter is multi-character

false

localeSensitive

boolean

false

Sort based on local rules

callback

any

false

Optional function to use for sorting - if the sort type is a closure, it will be recognized as a callback

Examples

Simple example for listSort function

Uses the listSort() function to get the list which sorted by type text(case-sensitive)

Run Example

list = "BOXLANG,boxlang,adobe,Boxlang,RAILO";
sortList = listSort( list, "Text", "desc" );
writeOutput( sortList );

Result: boxlang,adobe,RAILO,Boxlang,BOXLANG

Example for listSort function with delimiters

Uses the listSort() function with delimiters to get the list which sorted by type numeric

Run Example

list = "10;20;-99;46;50";
sortList = listSort( list, "Numeric", "asc", ";" );
writeOutput( sortList );

Result: -99;10;20;46;50

Simple Example for listSort function using sortType(textnocase)

Uses the listSort() function with delimiters to get the list which sorted by type textnocase(case-insensitive)

Run Example

list = "10|RED|yeLLow|-246|green|ORange";
sortList = listSort( list, "TextNoCase", "asc", "|" );
writeOutput( sortList );

Result: -246|10|green|ORange|RED|yeLLow

Additional Examples

Run Example

listNumeric = "4,-16,2,15,-5,7,11";
writeOutput( listsort( listNumeric, "numeric", "asc" ) );
writeOutput( "<br><br>" );
writeOutput( listsort( "Adobe/boxlang/Boxlang/15/LAS", "text", "desc", "/" ) );
writeOutput( "<br><br>" );
writeOutput( listsort( "Adobe,boxlang,boxlang,15,LAS", "textnocase", "asc" ) );
writeOutput( "<br><br>" );
// Member function
strList = "Boxlang,Boxlang,LAS,SUSI,AdoBe";
writeDump( strlist.listSort( "textnocase", "asc" ) );

Last updated

Was this helpful?