ColdFusion UDF Library - structToList
December 16th, 2008
«« Back to ColdFusion Library
Category:
STRUCT
Description:
Converts a structure to a list
Parameters:
Returns:
A list of name value pairs from the structure.
Requires:
Sample Use:
Copy to Clipboard
Category:
STRUCT
Description:
Converts a structure to a list
Parameters:
- struct (Struct, required)
The structure to convert into a compound list. - delimiter1 (String, Default: &)
The delimiter for the outer list. - delimiter2 (String, Default: =)
The delimiter for the inner list pairs.
Returns:
A list of name value pairs from the structure.
Requires:
Sample Use:
Copy to Clipboard
function structToList(struct){
var delimiter1 = "&";
var delimiter2 = "=";
var loop = 0;
var keys = structKeyArray(struct);
var value = arrayNew(1);
var pos = 0;
if (arrayLen(arguments) gte 2)delimiter1 = arguments[2];
if (arrayLen(arguments) gte 3)delimiter2 = arguments[3];
for (loop = 1; loop lte arrayLen(keys); loop = incrementValue(loop)){
pos = arrayLen(value)+1;
value[pos] = keys[loop] & delimiter2 & struct[keys[loop]];
};
return arrayToList(value,delimiter1);
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=81&function=structToList



