# ListSort

Sorts and delimits the items in a list according to the specified sort type and sort order.

### Syntax

    ListSort(list, sort_type [, sort_order] [, delimiter ])

##### list

List to be sorted. The items in the list must be separated by commas or otherwise delimited.

##### sort_type

The type of sort to be executed. You can specify any of the following sort types:

- Numeric - sorts numbers.
- Text - sorts text alphabetically.
- Textnocase - sorts text alphabetically. The case is ignored.

##### sort_order

The order to be followed. You can specify any of the following:

- Asc - (Default) Ascending sort order.
- Desc - Descending sort order.

##### delimiter

Specify the character(s) used to delimit elements in the list. Default is comma ( , ).

### Example

    <!--- This example shows how to use ListSort--->
    <HTML>
    <HEAD>
    <TITLE>ListSort Example</TITLE>
    </HEAD>

    <BODY>
    <H3>ListSort Example</H3>

    <!--- Find a list of users who wrote messages --->
    <CFQUERY NAME="GetMessageUser" DATASOURCE="cfsnippets">
    SELECT         Username, Subject, Posted
    FROM         Messages
    </CFQUERY>

    <CFSET myList = ValueList(GetMessageUser.UserName)>
    <P>Here is the unsorted list. </P>

    <CFOUTPUT>
    #myList#
    </CFOUTPUT>
    <P>Here is the list sorted alphabetically:</P>
    <CFSET sortedList = ListSort(myList, "Text")>
    <CFOUTPUT>
    #sortedList#
    </CFOUTPUT>

    <P>Here is a numeric list that is to be sorted in descending order.</P>
    <CFSET sortedNums = ListSort("12,23,107,19,1,65","Numeric", "Desc")>
    <CFOUTPUT>
    #sortedNums#
    </CFOUTPUT>

    <P>Here is a list that must be sorted numerically, since it contains both
    negative and positive numbers, as well as decimal numbers. </P>

    <CFSET sortedNums2 = ListSort("23.75;-34,471:100,-9745","Numeric",
    "ASC", ";,:")>

    <CFOUTPUT>
    #sortedNums2#
    </CFOUTPUT>

    <P>Here is a list that is to be sorted alphabetically without
    consideration of case.</P>

    <CFSET sortedMix = ListSort("hello;123,HELLO:jeans,-
    345,887;ColdFusion:coldfusion", "TextNoCase", "ASC", ";,:")>

    <CFOUTPUT>
    #sortedMix#
    </CFOUTPUT>

    </BODY>
    </HTML>