CFLib.org – Common Function Library Project

quotedListToArray(theList)

Last updated January 3, 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;	
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson