[Benjamin S. Rogers]
[How about the following:]

Aiight.  Devil's Advocate here, but if you're trying to hack search
functions for your arrays, you're probably not doing it right.  But, that's
just my opinion.  However, just as an exercise for the old noggin ...

Solutions when you do it infrequently:

ArrayFind(myArray,myString) =
ListFind(ArrayToList(myArray,Chr(1)),myString,Chr(1))
ArrayFindNoCase(myArray,myString) =
ListFindNoCase(ArrayToList(myArray,Chr(1)),myString,Chr(1))
ArrayContains(myArray,myString) =
ListContains(ArrayToList(myArray,Chr(1)),myString,Chr(1))
ArrayContainsNoCase(myArray,myString) =
ListContainsNoCase(ArrayToList(myArray,Chr(1)),myString,Chr(1))

NOw, if you are doing quite a number of lookups, in a loop for example, I
suggest you go with something a bit more efficient:

<!--- Do this part once --->
<CFSET myArrayLookup=StructNew()>
<CFLOOP FROM="1" TO="#ArrayLen(myArray)#" INDEX="i">
  <CFSET ThisKey=myArray[i]>
  <CFIF StructKeyExists(myArrayLookup,ThisKey)>
    <CFSET myArrayLookup[ThisKey]=ListAppend(myArrayLookup[ThisKey],i)>
  <CFELSE>
    <CFSET myArrayLookup[ThisKey]=i>
  </CFIF>
</CFLOOP>
<!--- These next parts are what you will do over and over, it's lightning
fast --->
<CFIF StructKeyExists(myArrayLookup,ThisKey)>
  <CFSET ArrayContains=True>
  <CFSET ArrayPositions=myArrayLookup[ThisKey]>
<CFELSE>
  <CFSET ArrayContains=False>
  <CFSET ArrayPositions=0>
</CFIF>

-Rick

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to