exact matches in an array 
Author Message
 exact matches in an array

Is there a way just to check if there is an exact match in
an array without having to loop through the entire array?

I've tried the Filter function, but that returns substring
matches too ... I want to be able to check if a value is
in the array before adding it to make sure there are no
duplicates in the array.

Here's an example of what I want:
daysarray= array("Monday","Tuesday","Wednesday")
' if I want to add "day", Filter returns all of the above
' but "day" is still not in the array

I want something that'll say: nope, "day" is not in the
array ... go ahead and add it

Thanks!
Candee



Sat, 18 Dec 2004 12:04:14 GMT  
 exact matches in an array
as i know without searching you can't get the exact values.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 18 Dec 2004 12:29:17 GMT  
 exact matches in an array
Here's one way.

You'll have to consider including LCase or UCase if you want eg Monday = monday

daysarray= array("Monday","Tuesday","Wednesday")
temp = "~" & join(daysarray,"~") & "~"

if instr(temp,"~day~") > 0 then msgbox "found": _
else msgbox "not in array... go ahead and add it"

--
Regards

Michael Dunn

: Is there a way just to check if there is an exact match in
: an array without having to loop through the entire array?
:
: I've tried the Filter function, but that returns substring
: matches too ... I want to be able to check if a value is
: in the array before adding it to make sure there are no
: duplicates in the array.
:
: Here's an example of what I want:
: daysarray= array("Monday","Tuesday","Wednesday")
: ' if I want to add "day", Filter returns all of the above
: ' but "day" is still not in the array
:
: I want something that'll say: nope, "day" is not in the
: array ... go ahead and add it
:
: Thanks!
: Candee



Sat, 18 Dec 2004 13:07:11 GMT  
 exact matches in an array
Have you considered using an associative dictionary?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/scri...
ml/jsobjDictionary.asp


Quote:
> Is there a way just to check if there is an exact match in
> an array without having to loop through the entire array?

> I've tried the Filter function, but that returns substring
> matches too ... I want to be able to check if a value is
> in the array before adding it to make sure there are no
> duplicates in the array.

> Here's an example of what I want:
> daysarray= array("Monday","Tuesday","Wednesday")
> ' if I want to add "day", Filter returns all of the above
> ' but "day" is still not in the array

> I want something that'll say: nope, "day" is not in the
> array ... go ahead and add it

> Thanks!
> Candee



Sat, 18 Dec 2004 16:41:29 GMT  
 exact matches in an array
Use the scripting.disctionary

dim dict
set dict  = createobject("scripting.dictionary")
dict.comparemode = vbTextCompare  ' mixed case matches..
dict.add "Monday","Hangover"
dict.add "Tuesday","Tired"
dict.add "Wednesday","Humpday"
if dict.exists("Thurday") then
   response.write "Blah alredy exists in the dictionary.."
else
   dict.add "Thursday", "this was not in the array.."
end if


Quote:
> Is there a way just to check if there is an exact match in
> an array without having to loop through the entire array?

> I've tried the Filter function, but that returns substring
> matches too ... I want to be able to check if a value is
> in the array before adding it to make sure there are no
> duplicates in the array.

> Here's an example of what I want:
> daysarray= array("Monday","Tuesday","Wednesday")
> ' if I want to add "day", Filter returns all of the above
> ' but "day" is still not in the array

> I want something that'll say: nope, "day" is not in the
> array ... go ahead and add it

> Thanks!
> Candee



Sat, 18 Dec 2004 21:12:39 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Exact match in 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