View comments | RSS feed

ListToArray

Description

Copies the elements of a list to an array.

Returns

An array

Category

Array functions, Conversion functions, List functions

Function syntax

ListToArray(list [, delimiters ])

See also

ArrayToList; Using Arrays and Structures in ColdFusion MX Developer's Guide

Parameters

Parameter Description

list

A list or a variable that contains one.

You define a list variable with a cfset statement.

delimiters

A string or a variable that contains one. ColdFusion treats each character in the string as a delimiter. The default value is comma.

Usage

ColdFusion ignores empty list elements; thus, the list "a,b,c,,,d" has four elements.

ColdFusion treats each character in the delimiters parameter as a separate delimiter. Therefore, if the parameter is ",+" ColdFusion will break the list at either a comma or a plus sign.

Example

<h3>ListToArray Example</h3>
<!--- Find a list of users who wrote messages --->
<cfquery name = "GetMessageUser" datasource = "cfdocexamples">
SELECT Username, Subject, Posted
FROM  Messages
</cfquery>
<cfset myList = ValueList(GetMessageUser.UserName)>
<p>My list is a list with <cfoutput>#ListLen(myList)#</cfoutput>
 elements.
<cfset myArrayList = ListToArray(myList)>
<p>My array list is an array with <cfoutput>#ArrayLen(myArrayList)#
 </cfoutput> elements.

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

Version 7

Comments


e.esquivel said on Aug 3, 2007 at 1:10 AM :
Lots of people are trying to get array from a list with empty values. A string method is not documented but very usefull to split (explode,convert to array) a list or we shoudld say a string.

There is a simple example that could prvent you to long time searches
<cfscript>
myString="one,two,,,five,six,,,,ten";
myArray=myString.split(",");
</cfscript>

Dump the result then you will have a surprise.
I did not tested it with coldfusion 6 but it certainly depend of the JRE. It works with Coldfusion 7 and 8.
I.Am.Zorglub said on Oct 17, 2007 at 2:39 AM :
Many thanks, e.esquivel, for your tip, which seems to work also in CFMX 6.1.
Even better, you can use regular expressions to split the string. Try:
<cfscript>
myString="one,two,,,five,six,,,,ten;eleven";
myArray=myString.split("[,;]+");
</cfscript>
Great, huh?

 

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