CFLib.org – Common Function Library Project

quotedListToArray(theList)

Last updated January 03, 2007

author

Anthony Cooper

Version: 1 | Requires: CF7 | Library: StrLib

Description:
Like the ListToArray function but accepts quoted lists. Useful when reading from Quoted CSVs and the like.

Return Values:
Returns an array.

Example:

<cfset drinks = '"tea","coffee","vimto","bovril"' >
<cfset aDrinks = QuotedListToArray( drinks ) >

Parameters:

Name Description Required
theList The list to parse. Yes

Full UDF Source:

/**
 * Converts elements in a quoted list to an array.
 * 
 * @param theList      The list to parse. (Required)
 * @return Returns an array. 
 * @author Anthony Cooper (ant@outsrc.co.uk) 
 * @version 1, January 3, 2007 
 */
function quotedListToArray(theList) {
    var items = arrayNew( 1 );
    var i = 1;
    var start = 1;
    var search = structNew();
    var quoteChar = """";

    while(start LT len(theList)) {
        search = reFind('(\#quoteChar#.*?\#quoteChar#)|([0-9\.]*)', theList, start, true );
            
        if (arrayLen(search.LEN) gt 1) {
            items[i] = mid(theList, search.POS[1], (search.LEN[1])); //Extract string
            items[i] = reReplace(items[i], '^\#quoteChar#|\#quoteChar#$', "", "All" );     //Remove double quote character
            start = search.POS[1] + search.LEN[1] + 1;
            i = i + 1;
        }
        else {
            start = Len( theList );
        }
    }
        
    return items;    
}

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