CFLib.org – Common Function Library Project

listWithNullsToArray(parsedList[, delim])

Last updated July 21, 2009

author

Andy Jarrett

Version: 2 | Requires: CF5 | Library: StrLib

Description:
If your list contains 6 elements with 5 null values then the listToArray length would be 1. With this function you create an array with a length of 6 and the extra values filled with "null".

Return Values:
Returns an array.

Example:

<cfscript>
    newArray = listWithNullsToArray("andy|jarrett||andyjarrett.co.uk|","|");
    for(i=1;i lte arrayLen(newArray);i=i+1){
      writeOutput(newArray[i]&"<br>");
    }
</cfscript>

Parameters:

Name Description Required
parsedList List to parse. Yes
delim List delimeter. Defaults to a comma. No

Full UDF Source:

/**
 * Return an array from a list with null values.
 * v2 mod by Marc, fixes a list with a null in front
 * 
 * @param parsedList      List to parse. (Required)
 * @param delim      List delimeter. Defaults to a comma. (Optional)
 * @return Returns an array. 
 * @author Andy Jarrett (udf@thebluefrogcompany.net) 
 * @version 2, July 20, 2009 
 */
function listWithNullsToArray(parsedList) {
    var delim = ",";
    if((left(trim(parsedList),1)) EQ delim) parsedList = "null" & parsedList;
    if(arrayLen(arguments) gt 1) delim = arguments[2];
    while(find(delim&delim,parsedList)) parsedList = replace(parsedList,delim&delim,delim & "NULL" & delim,"ALL");
    if(right(parsedList,1) eq delim){
        parsedList = listAppend(parsedList,"NULL",delim);
    }
    return listToArray(parsedList,delim);
}

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