CFLib.org – Common Function Library Project

structValueList(struct[, delimiter])

Last updated November 6, 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;
}
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