TrimStruct(st[, excludeList])
Last updated July 11, 2002
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;
}
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