;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfStringExist (arrStrings, strTarget, blnMatchCase, blnMode) strTarget = ChrStringToUnicode (strTarget) ; Convert target string to unicode. hdlBBTarget = BinaryAlloc (StrByteCount (strTarget, -1)) BinaryPokeStrW (hdlBBTarget, 0, strTarget) intResult = -1 hdlBBSearch = BinaryAlloc (8) ; Allocate buffer for search string. intLast = ArrInfo (arrStrings, 1) - 1 For intI = 0 To intLast strSearch = ChrStringToUnicode (arrStrings[intI]) ; Convert search string to unicode. intByteCount = StrByteCount (strSearch, -1) If intByteCount > BinaryBufInfo (hdlBBSearch, 0) ; Enlarge search buffer when needed. hdlBBSearch = BinaryFree (hdlBBSearch) hdlBBSearch = BinaryAlloc (intByteCount) EndIf BinaryPokeStrW (hdlBBSearch, 0, strSearch) intResult = BinaryIndexBin (hdlBBTarget, 0, hdlBBSearch, @FWDSCAN, blnMatchCase) ; Get byte position in unicode target string. If intResult > -1 intResult = StrCharCount (BinaryPeekStrW (hdlBBTarget, 0, intResult, @FALSE)) ; Get character position in unicode target string. Break EndIf Next hdlBBSearch = BinaryFree (hdlBBSearch) hdlBBTarget = BinaryFree (hdlBBTarget) If !!blnMode Then Return 1 + intResult ; Return start character position of search string found in unicode target string. Return intResult > -1 ; Return boolean value whether search string has been found in target string or not. ;.......................................................................................................................................... ; This UDF "udfStringExist" checks the existence of one string or more strings within another string. ; ; Parameter blnMode controls, whether this function returns the start character position of the search string found in the unicode ; target string (counting starts from 1), or returns a boolean value, whether the search string has been found in the target string or not. ; ; Parameter: ; arrStrings ..... The dim-1 array of strings to search for. ; strTarget ...... The string to be searched. ; blnMatchCase ... @TRUE = Case-sensitive search. ; @FALSE = Case-insensitive search. ; blnMode ........ @TRUE = Return integer number of the start character position found within the unicode target string, or 0 if not found. ; @FALSE = Return boolean value for "Found" (@TRUE) or "Not Found" (@FALSE). ; ; Based on WinBatch Tech Data Base article "udfStringsExist", ; File Created: 2010:02:17:11:00:14, Last Updated: 2009:09:04:10:58:29, author unknown. ; ; (c)Detlev Dalitz.20120109. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. strTarget = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy Ð' ;strTarget = strTarget : ChrHexToUnicode ("A903A00395039B03") ; Extended target string. ; String: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy Ð ; Position: 000000000011111111112222222222333333333344444444445555555555666 ; 123456789012345678901234567890123456789012345678901234567890123 strStringsToLookFor1 = '- ! @ # $ %% & ^ * ( ) _ +' ; No match in target string. strStringsToLookFor2 = 'a b c' ; Match. strStringsToLookFor3 = '0' ; Match. strStringsToLookFor4 = 'z' ; Match. strStringsToLookFor5 = 'Ð' ; Match. strStringsToLookFor6 = ChrHexToUnicode ("9B03") ; No match in target string, but match in extended target string. arrStrings1 = Arrayize (strStringsToLookFor1, " ") arrStrings2 = Arrayize (strStringsToLookFor2, " ") arrStrings3 = Arrayize (strStringsToLookFor3, " ") arrStrings4 = Arrayize (strStringsToLookFor4, " ") arrStrings5 = Arrayize (strStringsToLookFor5, " ") arrStrings6 = Arrayize (strStringsToLookFor6, " ") blnMatchCase = @TRUE blnMode = @TRUE blnResult11 = udfStringExist (arrStrings1, strTarget, blnMatchCase, blnMode) ; 0 blnResult12 = udfStringExist (arrStrings2, strTarget, blnMatchCase, blnMode) ; 37 blnResult13 = udfStringExist (arrStrings3, strTarget, blnMatchCase, blnMode) ; 1 blnResult14 = udfStringExist (arrStrings4, strTarget, blnMatchCase, blnMode) ; 0 blnResult15 = udfStringExist (arrStrings5, strTarget, blnMatchCase, blnMode) ; 63 blnResult16 = udfStringExist (arrStrings6, strTarget, blnMatchCase, blnMode) ; 0 (resp. 67 in extended target string) blnMatchCase = @FALSE blnMode = @TRUE blnResult21 = udfStringExist (arrStrings1, strTarget, blnMatchCase, blnMode) ; 0 blnResult22 = udfStringExist (arrStrings2, strTarget, blnMatchCase, blnMode) ; 11 blnResult23 = udfStringExist (arrStrings3, strTarget, blnMatchCase, blnMode) ; 0 blnResult24 = udfStringExist (arrStrings4, strTarget, blnMatchCase, blnMode) ; 36 blnResult25 = udfStringExist (arrStrings5, strTarget, blnMatchCase, blnMode) ; 63 blnResult26 = udfStringExist (arrStrings6, strTarget, blnMatchCase, blnMode) ; 0 (resp. 67 in extended target string) blnMatchCase = @TRUE blnMode = @FALSE blnResult31 = udfStringExist (arrStrings1, strTarget, blnMatchCase, blnMode) ; 0 blnResult32 = udfStringExist (arrStrings2, strTarget, blnMatchCase, blnMode) ; 1 blnResult33 = udfStringExist (arrStrings3, strTarget, blnMatchCase, blnMode) ; 1 blnResult34 = udfStringExist (arrStrings4, strTarget, blnMatchCase, blnMode) ; 0 blnResult35 = udfStringExist (arrStrings5, strTarget, blnMatchCase, blnMode) ; 1 blnResult36 = udfStringExist (arrStrings6, strTarget, blnMatchCase, blnMode) ; 0 (resp. 1 in extended target string) blnMatchCase = @FALSE blnMode = @FALSE blnResult41 = udfStringExist (arrStrings1, strTarget, blnMatchCase, blnMode) ; 0 blnResult42 = udfStringExist (arrStrings2, strTarget, blnMatchCase, blnMode) ; 1 blnResult43 = udfStringExist (arrStrings3, strTarget, blnMatchCase, blnMode) ; 1 blnResult44 = udfStringExist (arrStrings4, strTarget, blnMatchCase, blnMode) ; 1 blnResult45 = udfStringExist (arrStrings5, strTarget, blnMatchCase, blnMode) ; 1 blnResult46 = udfStringExist (arrStrings6, strTarget, blnMatchCase, blnMode) ; 0 (resp. 1 in extended target string) Exit