CFLib.org – Common Function Library Project

structToList(s[, delim])

Last updated July 25, 2006

author

Greg Nettles

Version: 2 | Requires: CF5 | Library: DataManipulationLib

Description:
Converts a struct into a delimed key/value list. Defult delimiter is "&" but any character can be used by passing it as a second argument.

Return Values:
Returns a string.

Example:

<!--- Create Struct --->
<cfset user=structNew()>
<cfset user.firstname="John">
<cfset user.lastname="Smith">
<cfset user.age=35>
<cfdump var="#user#" label="user">

<!--- Call Function --->
<br>
Using defult delimiter:
<br>
<cfset myList = structToList(user)>
<cfdump var="#myList#">
<br><br>
Using custom delimiter:
<br>
<cfset myList2 = structToList(user,"@")>
<cfdump var="#myList2#">

Parameters:

Name Description Required
s Structure. Yes
delim List delimeter. Defaults to a comma. No

Full UDF Source:

/**
 * Converts struct into delimited key/value list.
 * 
 * @param s 	 Structure. (Required)
 * @param delim 	 List delimeter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Greg Nettles (gregnettles@calvarychapel.com) 
 * @version 2, July 25, 2006 
 */
function structToList(s) {
	var delim = "&";
	var i = 0;
	var newArray = structKeyArray(arguments.s);

	if (arrayLen(arguments) gt 1) delim = arguments[2];

	for(i=1;i lte structCount(arguments.s);i=i+1) newArray[i] = newArray[i] & "=" & arguments.s[newArray[i]];

	return arraytoList(newArray,delim);
}
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