Instr With a Wildcard

Joshann

Registered User.
Local time
Today, 02:51
Joined
Mar 22, 2002
Messages
142
Is it possible to use a wildcard with the Instr() function?

For example, if I want to determine if a string contains a string that has any alphabetic character followed by a hyphen, how would I do that? I need to use a wildcard because I want it to return false if the string contains a space followed by a hyphen. I only want it to return true if there is an alphabetic character followed by a hyphen.

The following doesn't work:
Code:
If Instr(strLookingIn, "?" & "-") > 0 Then
 
? includes all characters:
Code:
If strLookingIn Like "*?-*" Then

Return true for all letters in the range a-Z:
Code:
If strLookingIn Like "*[a-Z]-*" Then True


If you're just looking for the <space> then hyphen:
Code:
If strLookingIn Like "* -*" Then False
 
Last edited:
Thanks. That should work.
 

Users who are viewing this thread

Back
Top Bottom