CFLib.org – Common Function Library Project

structFindKeyMatch(scope, keyword)

Last updated August 26, 2011

author

Jeff Gladnick

Version: 1 | Requires: CF6 | Library: DataManipulationLib

Description:
Structfindkey is great if you know the "key" name you're looking for, but what if you only have a part of the key name. This function solves your problem.

Return Values:
Returns an array.

Example:

<cfset jeff=structnew() />
<cfset jeff.addonPartnerId_20_1 = "addon1" />
<cfset jeff.addonPartnerId_20_2 = 2  />
<cfset jeff.addonPartnerId_18_2 = 3  />
<cfset jeff.addonPartnerId_20_3 = 4   />
<cfset jeff.blah = 5 />
<cfdump var="#jeff#">
<cfdump var="#structFindKeyMatch(jeff,'addonPartnerId')#">

Parameters:

Name Description Required
scope Structure to search. Yes
keyword Keyword to search for. Yes

Full UDF Source:

<!---
 Like structFindKey except it matches a pattern.
 
 @param scope      Structure to search. (Required)
 @param keyword      Keyword to search for. (Required)
 @return Returns an array. 
 @author Jeff Gladnick (jeff@greatdentalwebsites.com) 
 @version 1, August 25, 2011 
--->
<cffunction name="structFindKeyMatch" returntype="array" output="false">
    <cfargument name="scope" type="struct" required="true">
    <cfargument name="keyword" type="string" required="true">
    
    <cfset var key = "">
    <cfset var i = "">
    <cfset var result = arrayNew(1)>    
    <cfset var tempstruct = structNew() />
    
    <cfloop index="i" list="#StructKeyList(arguments.scope)#" delimiters=",">  
        <cfif findNoCase(arguments.keyword,i)>
            <cfset tempstruct[i] = arguments.scope[i]>
            <cfset arrayAppend(result, duplicate(tempstruct)) />    
        </cfif>
    
        <cfset structClear(tempstruct) />
    </cfloop>
    
    <cfreturn result>
        
</cffunction>

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

Created by Raymond Camden / Design by Justin Johnson