Avg. Rating 2.0

Problem

You need to remove white-spaces from Form or URL struct or any other struct.

Solution

Loop through the struct and use trim function to remove white-spaces.

Detailed explanation

Use the StructTrimAllKeys(<struct>) function defined and explained here:

 

Function (updated as per Phill's comment):

<cffunction name = "StructTrimAllKeys" returntype="struct"
hint="">

 <cfargument name = "structVal"  type = "struct"  required =
"yes" /> 
 <cfset var key = "" />
 <!--- loop all keys in the struct and if its a simple value,
trim() it. --->
 <cfloop collection="#structVal#" item="key">
  <cfif IsSimpleValue(structVal[key])>
    <cfset structVal[key] = trim(structVal[key]) />
  </cfif>
 </cfloop>

 <cfreturn structVal />

</cffunction>

 

Example usage:

<cfoutput>

#StructTrimAllKeys(Form)#

</cfoutput>

<cfoutput>

#StructTrimAllKeys(URL)#

</cfoutput>

 

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes