Exact match in array? 
Author Message
 Exact match in array?

A dictionary object would probably be more efficient for what you're
trying to do.

Dim Dictionary
Dim MyIndex(0)
Set Dictionary = CreateObject("Scripting.Dictionary")
Dictionary("Fred") = 0
Dictionary("Hilidays with Fred") = 1
Dictionary("Killing Fred") = 2
Dictionary("Fred and Jane go to Town") = 3
If Dictionary.Exists("Fred") Then
    MyIndex(0) = "Fred"
End If
MsgBox MyIndex(0)


| What the most efficient way to seacrh for an exact match in an array
in VBS?
| I know I can run a for/next loop up to the Ubound of the array, but I
was
| hoping there was something neater?
|
| I was going to use the filter function....but....according to the
| documentation and examples this does substring matches, which I DONT
want. I
| only want a match if the entire array item exactly matches the
comparison
| stirng.
|
| This a M$s example:
| Dim MyIndex
| Dim MyArray (3)
| MyArray(0) = "Sunday"
| MyArray(1) = "Monday"
| MyArray(2) = "Tuesday"
| MyIndex = Filter(MyArray, "Mon") ' MyIndex(0) contains "Monday".
| This would be useless to me. I am looking for book titles, where it is
quite
| possible for many titles to contain the same substring.
| eg
| Dim MyIndex
| Dim MyArray (4)
| MyArray(0) = "Fred"
| MyArray(1) = "Hilidays with Fred"
| MyArray(2) = "Killing Fred"MyArray(3) = "Fred and Jane go to Town"
| MyIndex = Filter(MyArray, "Fred") => I only want to contain
MyArray(0)Is
| this possble of must I resort to stepping through the array?Al Blake,
| Australia
|
|
|
|
|



Wed, 29 Oct 2003 18:52:43 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. exact matches in an array

2. Seek Nearest Match if exact match not found ?

3. Seek Nearest Match if exact match not found ?

4. Checking strings for exact match

5. non-exact matches

6. Using FIND method to get Exact match

7. using Find Method for Exact match

8. newbie: array to function getting type mis-match

9. match word in array cells

10. Matching arrays?

11. RegExp question: match within another match

12. exact & hi-res laser printer

 

 
Powered by phpBB® Forum Software