ListSetAt

Description

Returns list with value assigned to its element at specified position.

Category

List functions

Syntax


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

See also

ListDeleteAt, ListGetAt, ListInsertAt

Parameters

Parameter
Description
list
A list.
position
A position. The first position in a list is denoted by the number 1.
value
A value.
delimiters
Set of delimiters.

Usage

When assigning an element to a list, ColdFusion inserts a delimiter. If delimiters contains more than one delimiter, ColdFusion defaults to the first delimiter in the string, or a comma, if delimiters was omitted.

If you intend to use list functions on strings that are delimited by the conjunction ", " (comma-space), as is common in HTTP header strings such as the COOKIE header, we recommend that you specify delimiters to include both comma and space, because ColdFusion Server does not skip white space.


Note

ColdFusion ignores empty list elements; thus, a list that is defined as "a,b,c,,,d" is treated as a four element list.


Example

<!--- This example shows ListSetAt --->

<html>

<head>

<title>ListSetAt Example</title>

</head>



<body>

<H3>ListSetAt Example</H3>



<!--- Find a list of users who wrote messages --->

<cfquery name = "GetMessageUser" datasource = "cfsnippets">

SELECT Username, Subject, Posted

FROM  Messages

</cfquery>



<cfset temp = ValueList(GetMessageUser.Subject)>





<!--- loop through the list and show it with ListGetAt --->

<H3>This is a list of <cfoutput>#ListLen(temp)#</cfoutput>

subjects posted in messages.</H3>



<cfset ChangedItem = ListGetAt(temp, 2, ",")>

<cfset TempToo = ListSetAt(temp, 2, "I changed this subject", ",")>

<UL>

<CFLOOP From = "1" To = "#ListLen(temptoo)#" INDEX = "Counter">

  <cfoutput><LI>(#Counter#) SUBJECT: #ListGetAt(temptoo, Counter)#

  </cfoutput>

</CFLOOP>

</UL>

<P>Note that item 2, "<cfoutput>#changedItem#</cfoutput>", has

been altered to "I changed this subject" using ListSetAt.



</body>

</html>



Banner.Novgorod.Ru