VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Wildcard Matcher

by gridrun (2 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This code matches a given string against a pattern which may contain the well known wildcards * and ?, whereas * represents any number of characters, including none, and ? represents any single character. You may want to paste the code into a class module :)

Inputs
Name as String, Pattern as String. Name is the String you want to match against Pattern.
Assumes
MatchCase() is the case-sensitive worker function. It makes usage of PreparePattern() to escape the characters # and [ (read Side effects). Match() is just a wrapper for MatchCase() which does a LCase() on both Name and Pattern parameters.
Code Returns
Returns Boolean True if String matches for Pattern, else returns Boolean False.
Side Effects
This code is written specifically for usage in an IRC bot, thus does escape certain chars which are recognized by the "Like" operator, which this code builds on. Namely, # and [ are taken literally rather than being interpreted as wildcards.

Rate Wildcard Matcher

Public Function Match(Name As String, Pattern As String) As Boolean
  If MatchCase(LCase(Name), LCase(Pattern)) Then Match = True
End Function

Public Function MatchCase(Name As String, Pattern As String) As Boolean
  Pattern = PreparePattern(Pattern)
  If Name Like Pattern Then MatchCase = True
End Function
Private Function PreparePattern(Pattern As String) As String
  Pattern = Replace(Pattern, "[", "[[]")
  Pattern = Replace(Pattern, "#", "[#]")
  PreparePattern = Pattern
End Function

Download this snippet    Add to My Saved Code

Wildcard Matcher Comments

No comments have been posted about Wildcard Matcher. Why not be the first to post a comment about Wildcard Matcher.

Post your comment

Subject:
Message:
0/1000 characters