listLast

Description

Gets the last element of a list.

Categories

Related

Syntax

ListLast(list [, delimiters, includeEmptyValues ])

Attributes

AttributeDescriptionRequiredDefault
delimitersA string or a variable that contains one. Characters that separate list elements. The default value is comma. If this parameter contains more than one character, ColdFusion processes each occurrence of each character as a delimiter; you cannot specify a multicharacter delimiter.
includeEmptyValuesOptional. Set to yes to include empty values.
listA list or a variable that contains a list.

Returns

The last element of the list.

Usage

If you use list functions on strings that separated by a delimiter character and a space, a returned list element might contain a leading space; use the trim function to remove leading and trailing spaces from a returned element. For example, consider this list:
<cfset myList = "one hundred, two hundred, three hundred"> To get a value from this list, use the trim function to remove the space before the returned value:
<cfset MyValue = #trim(ListLast(myList)#> With this usage, the MyValue variable gets the value "three hundred", not " three hundred", and spaces within a list element are preserved.
ColdFusion ignores empty list elements; thus, the list "a,b,c,,,d" has four elements.

Example

<h3>ListFirst, ListLast, and ListRest Example</h3> 
<!--- Find a list of users who wrote messages ---> 
<cfquery name = "GetMessageUser" datasource = "cfdocexamples"> 
    SELECT Username, Subject, Posted 
    FROMMessages 
</cfquery> 
<cfset temp = ValueList(GetMessageUser.Username)> 
Before editing the list, it is:&nbsp; 
<cfoutput>#ValueList(GetMessageUser.Username)#</cfoutput>.  
(Users who posted more than once are listed more than once.) 
<!--- Show the first user in the list ---> 
The first user in the list is: <cfoutput>#ListFirst(temp)#</cfoutput> 
The rest of the list is:&nbsp;<cfoutput>#ListRest(temp)#</cfoutput>. 
(Users who posted more than once are listed more than once.) 
The last user in the list is: <cfoutput>#ListLast(temp)#</cfoutput>