ListAppend

Description

Concatenates a list or element to a list.

Returns

A string.

Category

List functions

Function syntax

ListAppend(list, value [, delimiter, includeEmptyFields ])

See also

ListPrependListInsertAtListGetAtListLastListSetAt; Lists in the Developing ColdFusion Applications.

History

ColdFusion (2018 release) Update 5:

  • Introduced named parameters.
  • New parameter added- includeEmptyFields.

Parameters

Parameter

Description

list

A list or a variable that contains a list. 

value

An element or a list of elements.

delimiters

(Optional) A 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 uses only the first character.

includeEmptyFields

Boolean to determine to include empty fields from the list that is appended to the list.

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 1

<cfscript>
       myList="John,Paul,George,Ringo";
       myListAppended=ListAppend(myList,"George Martin",","); // Delimiter is comma
       WriteOutput(myListAppended);
</cfscript>

Output

John,Paul,George,Ringo,George Martin

Example 2

 

<cfscript> 
       // define the list 
       myList="John,Paul,George,Ringo"; 
       myListAppended=ListAppend(myList,"George Martin");  
       WriteOutput(myListAppended); 
</cfscript>

Output

John,Paul,George,Ringo,George Martin

Example 3

<cfscript> 
       myList="John"; 
       myListAppended=ListAppend(myList,"George Martin","|");  
       WriteOutput(myListAppended); 
</cfscript>

Output

John|George Martin

Example 3

When includeEmptyFields="true",

<cfscript> 
 mylist="John,Paul,George" 
 writeOutput(ListAppend(list=mylist,value="Ringo,,",delimiter=",",includeEmptyFields="true")) 
</cfscript>

Output

John,Paul,George,Ringo,,

<cfscript> 
 mylist="John,Paul" 
 writeOutput(ListAppend(list=mylist,value="Ringo,George,",delimiter=",",includeEmptyFields="true")) 
</cfscript>

Output

John,Paul,Ringo,George,

Example 4

When includeEmptyFields="false",

<cfscript> 
 mylist="John,Paul,George" 
 writeOutput(ListAppend(list=mylist,value="Ringo,,",delimiter=",",includeEmptyFields="false")) 
</cfscript>

Output

John,Paul,George,Ringo

<cfscript> 
 mylist="John,Paul" 
 writeOutput(ListAppend(list=mylist,value="Ringo,George,",delimiter=",",includeEmptyFields="false")) 
</cfscript>

Output

John,Paul,George,Ringo

Member function

<cfscript> 
 mylist="John,Paul,," 
 writeOutput(mylist.Append("Ringo,George,",",","false")) 
</cfscript>

Output

John,Paul,Ringo,George

Логотип Adobe

Увійдіть до облікового запису