Cool.  I actually searched cflib for "trim structure" and "trim struct" 
before writing mine!

I guess I should've googled instead of using the search feature on cflib.

Rick


[EMAIL PROTECTED] wrote:
> Rick,
> 
> This one is on www.cflib.org:
> 
> <cfscript>
> /**
>  * 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 ([EMAIL PROTECTED]) 
>  * @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;
> }
> </cfscript>
> 
> 
> -----Original Message-----
> From: Rick Root [mailto:[EMAIL PROTECTED]
> Sent: Friday, July 22, 2005 3:24 PM
> To: CF-Talk
> Subject: trimStructValues
> 
> 
> Does anyone have any comments on this?  I was looking for a way to 
> easily trim all of the simple values in a structure and came up with the 
> following, which I thought would be useful for trimming scopes like the 
> form scope or the arguments scope.
> 
> It seems to work.
> 
> Rick
> 
> 
> <cffunction name="trimStructValues" access="public" output="no" 
> returnType="struct">
>       <cfargument name="myStruct" type="struct" required="yes">
>       <cfargument name="recurse" type="boolean" required="no" default="false">
>       <cfscript>
>       var cnt = 1;
>       var myKeys = StructKeyArray(myStruct);
>       var myKey = "";
>       
>       for (cnt=1;cnt LTE arrayLen(myKeys); cnt = cnt + 1)
>       {
>               myKey = myKeys[cnt];
>               if (isSimpleValue(myStruct[mykey]))
>               {
>                       myStruct[mykey] = trim(myStruct[mykey]);
>               } else if ( isStruct(myStruct[mykey]) AND recurse) {
>                       myStruct[myKey] = trimStructValues(myStruct[myKey]);
>               }
>       }
>       return myStruct;
>       </cfscript>
> </cffunction>
> 
> 
> 
> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:212641
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to