Hi guys,
I'm looking for a function in VBA that returns TRUE if a given string matches a string with wildcards.
e.g. WILDCARDMATCH("worldwideweb", "*orl*idewe*") returns TRUE
Thanks a lot in advance!
Siebe
Hi guys,
I'm looking for a function in VBA that returns TRUE if a given string matches a string with wildcards.
e.g. WILDCARDMATCH("worldwideweb", "*orl*idewe*") returns TRUE
Thanks a lot in advance!
Siebe
try
Please Login or Register to view this content.
I'm not sure that that is accurate enough. I need a precise match, no errors allowed...
But thanks for the suggestion.
Siebe
If I can make others happy with it: here's the solution I ended up writing myself.
Basic philosophy:
1. Create a newString that has the same length as the string you're checking and that consists entirely of "*"'s
2. Divide the mask string (delimited by the wildcards) into components and search inside your seach string if they're there.
3. If a component from the mask actually appears to be part of your string, replace the same section in the 'newString' from step 1 with that component
4. Finally replace all double or multiple **'s by single *'s.
5. If the resulting 'new string' equals the mask string, you're successful!
Example:
1. Check JRRTolkien agains *RRTo*ie*
2. Create a new string of the original length, containing only *'s: **********
3. Split *RRTo**ie* by wildcard. This results in two strings: RRTo and ie
4. If RRTo appears in your search string, replace the same sequence in the new string: ********** becomes *RRTo*****
5. If ie appears in your string, replace the same sequence in the new string: *RRTo***** becomes *RRTo**ie*
6. Replace all double appearances of * by single *. *RTo**ie* becomes *RTo*ie*
7. The result ends up being equal to the original mask provided, so return TRUE.
Note: the only thing I didn't provide is the function for parsing the mask.
I assume however that alternatives are not too hard to create e.g. using the SPLIT-function.
Please Login or Register to view this content.
Last edited by SiebeBosch; 12-08-2013 at 06:34 PM. Reason: minor corrections
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks