1 | ListAppend (list, value [, delimiter, includeEmptyFields ]) |
See also
ListPrepend, ListInsertAt, ListGetAt, ListLast, ListSetAt; 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
1 2 3 4 5 | < cfscript > myList= "John,Paul,George,Ringo" ; myListAppended= ListAppend (myList, "George Martin" , "," ); // Delimiter is comma WriteOutput (myListAppended); </ cfscript > |
1 2 3 4 5 6 | < cfscript > // define the list myList= "John,Paul,George,Ringo" ; myListAppended= ListAppend (myList, "George Martin" ); WriteOutput (myListAppended); </ cfscript > |
1 2 3 4 5 | < cfscript > myList= "John" ; myListAppended= ListAppend (myList, "George Martin" , "|" ); WriteOutput (myListAppended); </ cfscript > |
1 2 3 4 | < cfscript > mylist= "John,Paul,George" writeOutput ( ListAppend (list=mylist,value= "Ringo,," ,delimiter= "," ,includeEmptyFields= "true" )) </ cfscript > |
1 2 3 4 | < cfscript > mylist= "John,Paul" writeOutput ( ListAppend (list=mylist,value= "Ringo,George," ,delimiter= "," ,includeEmptyFields= "true" )) </ cfscript > |
1 2 3 4 | < cfscript > mylist= "John,Paul,George" writeOutput ( ListAppend (list=mylist,value= "Ringo,," ,delimiter= "," ,includeEmptyFields= "false" )) </ cfscript > |
1 2 3 4 | < cfscript > mylist= "John,Paul" writeOutput ( ListAppend (list=mylist,value= "Ringo,George," ,delimiter= "," ,includeEmptyFields= "false" )) </ cfscript > |
1 2 3 4 | < cfscript > mylist= "John,Paul,," writeOutput (mylist.Append( "Ringo,George," , "," , "false" )) </ cfscript > |