On Sep 25, 2006, at 1:50 PM, Dr Gerard Hammond wrote:
Can I look for a fragment of a key from a dictionary?
A Dictionary is designed to work on a Hash table, and that hash is
generated based on the entire Key. In addition, each Key needs to be
unique so you cannot have a field for "A" without a subdictionary
(which would be slow) to include values like "Aaron" and "Apple".
What I would do is take advantage of the Keys() array, and use InStr
(or InStrB for case-sensitive searches).
Extend your Dictionary, or create a subclass to return a Subset of
Keys (as array) based on the search string. No choice but to loop
through each Key in the Array so it will not be as fast as a Hash...
but will give you the results you want:
Function KeyStartsWithString(Extends d As Dictionary) As String()
Dim matchedList() As String
For Each v As Variant In d.Keys
If (v.Type = Variant.TypeString) Then
// want to limit the match to beginning of string
If v.StringValue.InStr(searchStr) = 1 Then matchedList.Append(s)
End If
Next
Return matchedList
End Function
You can add KeyStartsWithStringB(), KeyContainsString(), and
KeyContainsStringB() if you want.
Just remember that performance is dependent on the size of the
Dictionary.Keys() array.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>