Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your approach is interesting but very inefficient even once corrected. An efficient implementation of the wildcard matching algorithm uses an extension of the <a href="http://en.wikipedia.org/wiki/Bitap_algorithm" rel="noreferrer"><strong>shift-or algorithm</strong></a> (according to Wikipedia also called “bitap” by some sources, but I’ve never read that myself).</p> <p>The only change to the conventional shift-or algorithm is in the preprocessing: For each <code>*</code> that you encounter in the pattern, enable <em>all</em> characters in the alphabet at this position.</p> <p>If you want to correct your own algorithm, then replace the <code>Contains</code> call by <code>IndexOf</code>, 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.</p> <p><strong>But all of this is unnecessary</strong> since VB already provides the necessary operator: <strong><code>Like</code></strong></p> <pre><code>If fullString Like wildcardString Then ' Yep, matches. End If </code></pre> <hr> <p>A note on style:</p> <p>Always initialise variables when you declare them, do not separate declaration and initialisation needlessly.</p> <p>That is, write</p> <pre><code>Dim stringParts As String() = wildcardString.Split("*") ' or, with Option Infer On: Dim stringParts = wildcardString.Split("*") </code></pre> <p>Furthermore, it makes no sense to compare a Boolean with a literal (<code>If X = False</code> …). Just write</p> <pre><code>If fullString.Contains(str) Then </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload