Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: UDF Wildcard String Compare
;************************************************************************************ ; Compare a Text String to a wildcard. ; Return @TRUE if it matches, @FALSE if no match. ; ; * ... zero or more of any characters at this point ; ? ... one of any character at this point. ; ;************************************************************************************ #DefineFunction WildStringCompare(Text, Wild) if (Wild == "") then return @TRUE ; Empty wildcard = TRUE if (Wild == "*") then return @TRUE ; "*" matches anything while (1) if (Wild == "") ; if end of wildcard is also if (Text == "")then return @TRUE ; end of Text, we match. return @FALSE; endif Cw = StrSub(Wild,1,1) ; Character of wildcard if (Cw == '*') ; Is it "*"? Wild = StrSub(Wild,2,-1) ; Bump wildcard to next position. while (1) ; See if we can match the rest if (WildStringCompare(Text, Wild)) then Return @TRUE if (Text == "") then Return @FALSE Text = StrSub(Text,2,-1) endwhile endif if (Cw == '?') ; A question mark matches anything if (Text == "") Then Return @FALSE; Text = StrSub(Text,2,-1) Wild = StrSub(Wild,2,-1) continue; endif if (StrSub(Text,1,1) != Cw) Then Return @FALSE; Wild = StrSub(Wild,2,-1) Text = StrSub(Text,2,-1) endwhile #EndFunction
Article ID: W15324
File Created: 2004:05:17:10:34:50
Last Updated: 2004:05:17:10:34:50