ListToStructRepeatKeys(list[, delimiter])
Last updated August 03, 2005
Version: 2 | Requires: CF5 | Library: DataManipulationLib
Description:
Based on ListToStruct() from Rob Brooks-Bilson, this one allows the structure key to be repeated. In the case of multiple values for a particular key, a comma-delimited list is created. Useful for parsing strings such as LDAP DNs, which may contain multiple values for a single key.
Return Values:
Returns a struct.
Example:
<cfset tempIn = "a=1;b=2;b=3;c=4">
<cfdump var="#ListToStructRepeatKeys(tempIn,";")#">
Parameters:
Name | Description | Required |
---|---|---|
list | List of key and value pairs. | Yes |
delimiter | List delimiter. Defaults to a comma. | No |
Full UDF Source:
/**
* Based on ListToStruct() from Rob Brooks-Bilson, this one allows the structure key to be repeated and the value added to a list.
* Version 2 - Ray modified the code a bit and fixed a missing var.
*
* @param list List of key and value pairs. (Required)
* @param delimiter List delimiter. Defaults to a comma. (Optional)
* @return Returns a struct.
* @author Tony Brandner (tony@brandners.com)
* @version 2, August 3, 2005
*/
function listToStructRepeatKeys(list){
var myStruct=StructNew();
var i=0;
var delimiter=",";
var tempVar="";
if(arrayLen(arguments) gt 1) delimiter = arguments[2];
for(i=listLen(list, delimiter); i gt 0; i=i-1) {
tempVar = trim(listGetAt(list, i, delimiter));
if (structKeyExists(myStruct,listFirst(tempVar, "="))) {
myStruct[listFirst(tempVar, "=")] = listAppend(myStruct[listFirst(tempVar, "=")],listLast(tempVar, "="));
} else {
myStruct[listFirst(tempVar, "=")] = listLast(tempVar, "=");
}
}
return myStruct;
}
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