CFLib.org – Common Function Library Project

structValueList(struct[, delimiter])

Last updated November 07, 2006

author

Kit Brandner

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Converts a structure into a key/value pair list. Ignores complex values (nested structures, arrays, etc.).

Return Values:
Returns a string.

Example:

<cfoutput>#structValueList(CGI)#</cfoutput>

Parameters:

Name Description Required
struct Structure to list. Yes
delimiter Delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Converts a structure into a key/value pair list.
 * 
 * @param struct      Structure to list. (Required)
 * @param delimiter      Delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Kit Brandner (kit.brandner@serebra.com) 
 * @version 1, November 6, 2006 
 */
function structValueList(struct) {
    var delimiter = ",";
    var element = 0;
    var kvName = "";
    var kvValue = "";
    var returnList = "";
        
    if(arrayLen(arguments) gt 1) delimiter = arguments[2];
        
    if (isStruct(struct)) {
        for (; element lt listLen(structKeyList(struct, delimiter)) ; element=element+1) {
            kvName = listGetAt(structKeyList(struct, delimiter), element+1, delimiter);
            kvValue = "";
            if(isSimpleValue(struct[kvName])) kvValue = struct[kvName];
            returnList = listAppend(returnList, kvName & iif(len(trim(kvValue)) gt 0, de("=" & kvValue), de("")));
        }
    }
    
    return returnList;
}

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