udfStrCompareWild
bln udfStrCompareWild (str, str, bln)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrCompareWild (strString, strPattern, blnMatchCase)
If strPattern == "" Then Return @TRUE ; Empty wildcard matches anything.
If strPattern == "*" Then Return @TRUE ; An asterisk "*" matches anything.
If !blnMatchCase
   strPattern = StrLower (strPattern)
   strString = StrLower (strString)
EndIf
While @TRUE
   If strPattern == "" Then Return strString == "" ; If end of wildcard is also.

   strPatternChar = StrSub (strPattern, 1, 1) ; Character of wildcard.

   If strPatternChar == "*"  ; An asterisk "*" matches anything.
      strPattern = StrSub (strPattern, 2, -1) ; Bump wildcard to next position.
      While @TRUE ; Try to match the rest.
         If udfStrCompareWild (strPattern, strString, blnMatchCase) Then Return @TRUE ; Recursive udf call.
         If strString == "" Then Return @FALSE
         strString = StrSub (strString, 2, -1)
      EndWhile
   EndIf

   If strPatternChar == "?" ; A question mark "?" matches any alpha or numeric character.
      If strString == "" Then Return @FALSE
      strString = StrSub (strString, 2, -1)
      strPattern = StrSub (strPattern, 2, -1)
      Continue
   EndIf

   If strPatternChar == "#" ; A "#" matches any numeric character.
      strStringChar = StrSub (strString, 1, 1)
      If strStringChar > "9" Then Return @FALSE
      If strStringChar < "0" Then Return @FALSE
      strString = StrSub (strString, 2, -1)
      strPattern = StrSub (strPattern, 2, -1)
      Continue
   EndIf

   If StrSub (strString, 1, 1) != strPatternChar Then Return @FALSE
   strString = StrSub (strString, 2, -1)
   strPattern = StrSub (strPattern, 2, -1)

EndWhile
;..........................................................................................................................................
; This UDF compares a text string to a wildcard string,
; returning @TRUE if the match is successful.
;
; This matching routine uses the following wildcards:
; * ... Zero or more of any characters at this position.
; ? ... One of any character at this position.
; # ... One numeric character at this position.
;
; blnMatchCase = 0 ... Ignore uppercase.
; blnMatchCase = 1 ... Respect uppercase.
;..........................................................................................................................................
; Published by Alan Kreutzer
; WinBatch TechDatabase, UserDefinedFunctionLibrary, Wildcard UDF
; Slightly modified by Detlev Dalitz.20020531.20030705.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;Test.

blnCmpWild1 = udfStrCompareWild ("das13/2456", "???##/#*", 0) ; 1 (@TRUE)
blnCmpWild2 = udfStrCompareWild ("xyz99/8976", "???##/#*", 0) ; 1 (@TRUE)
blnCmpWild3 = udfStrCompareWild ("dasdas456" , "???##/#*", 0) ; 0 (@FALSE)
blnCmpWild4 = udfStrCompareWild ("dd45/6"    , "dd##/#*" , 1) ; 1 (@TRUE)
blnCmpWild5 = udfStrCompareWild ("dd45/6"    , "DD##/#*" , 1) ; 0 (@FALSE)
blnCmpWild6 = udfStrCompareWild ("dd45/6"    , "DD##/#*" , 0) ; 1 (@TRUE)

Exit
;------------------------------------------------------------------------------------------------------------------------------------------