View comments | RSS feed

ListGetAt

Description

Gets a list element at a specified position.

Returns

Value of the list element at position position.

Category

List functions

Function syntax

ListGetAt(list, position [, delimiters ])

See also

ListFirst, ListLast, ListQualify, ListSetAt; Lists in Using ColdFusion Variables in ColdFusion MX Developer's Guide

Parameters

Parameter Description

list

A list or a variable that contains one.

position

A positive integer or a variable that contains one. Position at which to get element. The first list position is 1.

delimiters

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

Usage

If you use list functions on strings that are delimited by a delimiter character and a space, a returned list element might contain a leading space; you use the trim function to remove such 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(listGetAt(myList, 2))#>

With this usage, MyValue = "two hundred", not " two 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>ListGetAt Example</h3>
<!--- Find a list of users who wrote messages --->
<cfquery name = "GetMessageUser" datasource = "cfdocexamples">
   SELECT Username, Subject, Posted
   FROM  Messages
</cfquery>
<cfset temp = ValueList(GetMessageUser.Username)>
<!--- loop through the list and show it with ListGetAt --->
<h3>This list of usernames who have posted messages numbers
<cfoutput>#ListLen(temp)#</cfoutput> users.</h3>
<ul>
<cfloop From = "1" To = "#ListLen(temp)#" index = "Counter">
   <cfoutput><li>Username #Counter#: #ListGetAt(temp, Counter)# </cfoutput>
</cfloop>
</ul>

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

Version 7

Comments


samihoda2 said on Jul 17, 2006 at 2:23 PM :
For delimiters it says:

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

If I have a parameter of "$|" it finds every $ and uses it as a delimiter, as expected from the desc above. But anyway to bypass that and have each occurance of "$|" together act as a delimiter?
Mediahouse said on Nov 16, 2006 at 6:48 PM :
Just use a character that cannot be found on the keyboard such as ╧, this character is achieved by holding ALT and pressing 1999 on your numpad.

 

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

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000555.htm