Skip to main content
December 9, 2008
Question

Find empty value on structure

  • December 9, 2008
  • 3 replies
  • 409 views
I'm assigning values to my structure dynamically and I need to find if one or more of the value(s) is/are empty string value
I tried to use :
<cfset aResults = #StructFindValue(mystruct,"", "all" )#> and I got what I wanted but now I'm not sure how can I refer back to the Key for those empty value(s)?

For example if this is my structure:
<CFSET str_mystruct= structNew()>
<CFSET str_mystruct["FN"}="Sylvia">
<CFSET str_mystruct["LN"}="Smith">
<CFSET str_mystruct["Add"}="">
<CFSET str_mystruct["City"}="Bladensburg">
<CFSET str_mystruct["zip"}="">

The StructFindValue function found 2 keys with empty values,they are Add and Zip
what is the syntax for CFIF condition, for example if Add or Zip keys is "" do something?


This topic has been closed for replies.

3 replies

Inspiring
December 10, 2008
If you want to remove all the empty keys form your structure, you can make use of the "RemoveEmptyStructureKeys" UDF...

http://cflib.org/udf/RemoveEmptyStructureKeys
December 9, 2008
Get the array of results from the function then loop over that array. The array will only contain results for blank keys. So something like:

<cfloop from="1" to="#ArrayLen(Variables.aResults)#" index="ARY">
<!--- Lets reset the blanks --->
<cfset str_mystruct[Variables.aResults[ARY]['key']] = 'blank' />
</cfloop>
Inspiring
December 9, 2008
Perhaps a better place for that if/else logic would be as you are populating the structure.