CFLib.org – Common Function Library Project

TrimStruct(st[, excludeList])

Last updated July 11, 2002

author

Mike Gillespie

Version: 3 | Requires: CF5 | Library: DataManipulationLib

Description:
Allows for trimming of all fields in a structure. Useful for automatically trimming the Form scope for example.

Return Values:
Returns a structure.

Example:

<cfscript>
st = structNew();
st.apple = "  Ray  ";
st.banana = "Camden";
st.leaveme = "           Foo ";
</cfscript>
<!--- use pass by rev --->
<cfset trimStruct(st,"leaveme")>
<cfoutput>
<pre>
<cfloop item="key" collection="#st#">
st.#key# = #st[key]#
</cfloop>
</pre>
</cfoutput>

Parameters:

Name Description Required
st Structure to trim. Yes
excludeList List of keys to exclude. No

Full UDF Source:

/**
 * Trims spaces from all keys in a structure.
 * Version 2 by Raymond Camden
 * Version 3 by author - he mentioned the need for isSimpleValue
 * 
 * @param st 	 Structure to trim. (Required)
 * @param excludeList 	 List of keys to exclude. (Optional)
 * @return Returns a structure. 
 * @author Mike Gillespie (mike@striking.com) 
 * @version 3, July 11, 2002 
 */
function TrimStruct(st) {
	var excludeList = "";
	var key = "";

	if(arrayLen(arguments) gte 2) excludeList = arguments[2];
	for(key in st) {
		if(not listFindNoCase(excludeList,key) and isSimpleValue(st[key])) st[key] = trim(st[key]);
	}
	return st;
}
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