View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > ListLast PreviousNext

ListLast

Gets the last element of a list.

The last element of the list.

List functions

ListLast(list [, delimiters ])

ListGetAt, ListFirst

Parameter

Description

list

A list or a variable that contains a list.

delimiters

A string or a variable that contains one. Character(s) that separate list elements. Default: 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.

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.

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

Contents > CFML Reference > ColdFusion Functions > ListLast PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


nick.endgame said on Oct 11, 2006 at 12:33 PM :
If you are trying to extract the email domain of an email address such as:

emailAddress = name@domain.com

you would write: <CFSET domainName = ListLast(emailAddress, "@")>

Posted by: Nick White - nick@endgamedevelopment.com

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functb14.htm