Description

Replaces the contents of a list element.

Returns

A copy of a list, with a new value assigned to the element at a specified position.

Category

List functions

Function syntax

ListSetAt(list, position, value [, delimiters, includeEmptyValues ])

See also

ListDeleteAtListGetAtListInsertAtLists in Data types- Developing guide in the Developing ColdFusion Applications

History

ColdFusion MX: Changed delimiter modification: ColdFusion MX does not modify delimiters in the list. (In earlier releases, in some cases, replaced delimiters with the first character in the delimiters parameter.)

Parameters

Parameter

Description

includeEmptyValues

Optional. Set to yes to include empty values.

list

A list or a variable that contains one.

position

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

value

An element or a list of elements.

delimiters

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 processes each occurrence of each character as a delimiter.

Usage

When assigning an element to a list, ColdFusion inserts a delimiter. If delimiters contains more than one delimiter, ColdFusion uses the first delimiter in the string, or, if delimiters was omitted, a comma. ColdFusion ignores empty list elements; thus, the list "a,b,c,,,d" has four elements.

Example

<cfscript>
    // case 1
    myList="Hulk,Superman,Batman,Joker"
    // replace Joker with Aquaman at position 4
    setAt=ListSetAt(myList,4,"Aquaman")
    writeOutput(setAt & "<br/>")
    // case 2: using a delimiter
    myList1="England|Spain|Germany|France"
    // replace Spain with Portugal at position 2
    setAt1=ListSetAt(myList1,2,"Portugal","|")
    writeOutput(setAt1)
</cfscript>

Output

Hulk,Superman,Batman,Aquaman
England|Portugal|Germany|France

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy