Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:55:42+00:00 2026-06-04T01:55:42+00:00

I have a method that takes 2 string arguments. One that contains a normal

  • 0

I have a method that takes 2 string arguments. One that contains a normal string and one that contains a string with one or more wildcard characters. I’ve tried the following code:

Private Function DoesMatchWildcardString(ByVal fullString As String, ByVal wildcardString As String) As Boolean
    Dim stringParts() As String
    Dim matches As Boolean = True

    stringParts = wildcardString.Split("*")

    For Each str As String In stringParts
        If fullString.Contains(str) = False Then
            matches = False
        End If
    Next

    Return matches

End Function

The I realized that it won’t work properly. If I have ABCD as a normal and A*CD as my wildcard string the match will work even if my normal string was CDAB, which is not what I want.

Any ideas??

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:55:44+00:00Added an answer on June 4, 2026 at 1:55 am

    Your approach is interesting but very inefficient even once corrected. An efficient implementation of the wildcard matching algorithm uses an extension of the shift-or algorithm (according to Wikipedia also called “bitap” by some sources, but I’ve never read that myself).

    The only change to the conventional shift-or algorithm is in the preprocessing: For each * that you encounter in the pattern, enable all characters in the alphabet at this position.

    If you want to correct your own algorithm, then replace the Contains call by IndexOf, and supply the position where it should start searching – namely, after the previous match. This will work for most cases, but it will perform a non-greedy search which might fail in some circumstances. An exhaustive search will necessarily backtrack. As I said, that’s inefficient, and the shift-or algorithm doesn’t suffer from this shortcoming.

    But all of this is unnecessary since VB already provides the necessary operator: Like

    If fullString Like wildcardString Then
        ' Yep, matches.
    End If
    

    A note on style:

    Always initialise variables when you declare them, do not separate declaration and initialisation needlessly.

    That is, write

    Dim stringParts As String() = wildcardString.Split("*")
    ' or, with Option Infer On:
    Dim stringParts = wildcardString.Split("*")
    

    Furthermore, it makes no sense to compare a Boolean with a literal (If X = False …). Just write

    If fullString.Contains(str) Then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that effectively takes a string. However, there is a very
I have a search method that takes in a user-entered string, splits it at
We have method that looks like this : public String getCommandString(Object...args) { return this.code
I have a method that takes a list of entities ( Class es) and
I have a method that takes an array of queries, and I need to
So I have a method that takes a tag and wraps the selected text
Say I want to have a method that takes any kind of number, is
All, I have a method that takes a date (YYYY-MM-DD H:M:S) from the database
I'm wondering how to go about testing this. I have a method that takes
I have a static method that takes a parameter and returns a class. the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.