View comments | RSS feed

ListAppend

Description

Concatenates a list or element to a list.

Returns

A copy of the list, with value appended. If delimiter = "", returns a copy of the list, unchanged.

Category

List functions

Function syntax

ListAppend(list, value [, delimiters ])

See also

ListPrepend, ListInsertAt, ListGetAt, ListLast, ListSetAt; Lists in Using ColdFusion Variables in ColdFusion MX Developer's Guide

Parameters

Parameter Description

list

A list or a variable that contains one.

value

An element or a list of elements.

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 uses only the first character.

Usage

ColdFusion inserts a delimiter character before value.

The following table shows examples of ListAppend processing:

Statement Output Comment
ListAppend('elem1,elem2', '' )

elem1,elem2,

Appended element is empty; delimiter is last character in list; list length is 2.

ListAppend('', 'elem1,elem2' )

elem1,elem2

List length is 2.

ListAppend
("one___two", "three", "___")

"one___two_three"

Inserted the first character of delimiters before "three."

Example

<h3>ListAppend Example</h3>
<!--- First, query to get some values for our list elements--->
<cfquery name = "GetParkInfo" datasource = "cfdocexamples">
SELECT PARKNAME,CITY,STATE
FROM PARKS WHERE PARKNAME LIKE 'AL%'
</cfquery>
<cfset temp = ValueList(GetParkInfo.ParkName)>
<cfoutput>
<p>The original list: #temp#
</cfoutput>
<!--- now, append a park name to the list --->
<cfset temp2 = ListAppend(Temp, "ANOTHER PARK")>
...

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

Version 7

Comments


cf.Objective said on Jun 20, 2005 at 10:24 AM :
This may be obvious to some, but it tripped me up... and the docs don't make it plain enough for my stilted brain. :)

In order for listAppend to work, it must be part of an explicit set operation:
<cfset myList = listAppend(myList,"someValue")>

One might assume that since the list container is named in the function call that <cfset listAppend(myList,"some Value")> would leave myList with an appended value... one may even spend several hours trying to troubleshoot code that used this technique. One would also, however, realize this does not work this way... hence one may feel quite silly.

So, one sends this post to the LiveDocs, hoping to save others a bit of trouble. Cheers!

 

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/00000547.htm