CFLib.org – Common Function Library Project

structFindKeyMatch(scope, keyword)

Last updated August 25, 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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson