CFLib.org – Common Function Library Project

ListNew()

Last updated January 12, 2004

author

Samuel Neff

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Converts the passed arguments array to a list and filters blanks. Helpful for creating lists from several values stored in different variables where some may be blank. Since it uses the arguments array as the source data for a list, there is no way to specify delimiters. To use custom delimiters use ListChangeDelims on the returned list.

Return Values:
Returns a list.

Example:

<cfparam name="form.var1" default="">
<cfparam name="form.var2" default="">
<cfparam name="form.var3" default="">

<cfset formValues = ListNew(form.var1, form.var2, form.var3)>

Parameters:

No arguments.

Full UDF Source:

/**
 * Creates a list from the passed arguments, skipping empty elements.
 * 
 * @return Returns a list. 
 * @author Samuel Neff (sam@serndesign.com) 
 * @version 1, January 12, 2004 
 */
function listNew() {
    var arr = arrayNew(1);
    var i = 1;

    for(;i lte arrayLen(arguments);i=i+1) {
        if(arguments[i] neq "") arr[arrayLen(arr)+1] = arguments[i];
    }
    
    return arrayToList(arr);
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson