ColdFusion Lists
A Coldfusion list (or any list for that matter) is simply a string. The thing that makes this string different (to any other string) is that it contains "delimiters'. Delimiters (sometimes referred to as "separators") are used to separate each item in the list.
For example: ColdFusion Lists,ColdFusion Arrays,ColdFusion Structures could be a "comma delimited", or "comma separated" list.
Although commas are the most common delimiter for lists, any character (or set of characters) can be used. For example, ColdFusion Lists:ColdFusion Arrays:ColdFusion Structures is no less a list than the comma delimited list.
Creating Lists in ColdFusion
This is easy. You can create a list in ColdFusion just the same you would create any other variable. Just remember to throw in a delimiter:
<cfset coldfusion_list = "ColdFusion Lists,ColdFusion Arrays,ColdFusion Structures">
In reality, you would probably create the list dynamically by looping through a set of items. You will often need to convert an array into a list or a list to an array (see below).
ColdFusion List Functions
Once you have your list, you can use ColdFusion to work with it. ColdFusion provides many functions for working with lists. Some of the common things you might need to do are listed below.
| Find out the list length: |
|
| Loop through the list: |
|
| Add items to the list: |
The above functions also accept an optional "delimiter" field, which, if needed, you place at the end. For example: |
| Find out if the list contains a given string: |
...or if you don't want it to be case sensitive:
|
| Convert a list into an array: |
|
| Convert an array into a list: |
|
