;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemLocateNC (strItem, strItemList, strDelimiter) Return ItemLocate (StrLower (strItem), StrLower (strItemList), strDelimiter) ;.......................................................................................................................................... ; This UDf udfItemLocateNC works as the native WinBatch function ItemLocate but the search is case-insensitive. ; The function finds the first occurrence of item in the specified list, ; and returns the position of the item (the first item in a list has a position of 1). ; If the item is not found, the function will return a 0. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemLocateWild (strPattern, strItemList, strDelimiter) strLocateList = "" intCount = ItemCount (strItemList, strDelimiter) For intElem = 1 To intCount strItem = ItemExtract (intElem, strItemList, strDelimiter) If (StrIndexWild (strItem, strPattern, 1) == 1) Then strLocateList = ItemInsert (strItem, -1, strLocateList, strDelimiter) Next Return strLocateList ;.......................................................................................................................................... ; This UDF udfItemLocateWild uses a given pattern string to search for similar items in a given itemlist, ; and returns an itemlist of items found. ; In the wildcard strPattern, "*" matches zero or more characters, and "?" matches any one character. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase) If !!blnMatchCase Then intPos = ItemLocate (strItem, strItemList, strDelimiter) Else intPos = ItemLocate (StrLower (strItem), StrLower (strItemList), strDelimiter) strItem = "" If intPos Then strItem = ItemExtract (intPos, strItemList, strDelimiter) Return strItem ;.......................................................................................................................................... ; This udfItemFetch searches case-insensitive for a given item in a given itemlist. ; If the item matches an item in the itemlist, then the item from the itemlist is returned otherwise an empty string. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. :Test1 ; udfItemLocateNC (strItem, strItemList, strDelimiter) strDelimiter = "," strItemList = "Monday,Sunday,Tuesday" strItem = "SuNdAy" intResult = udfItemLocateNC (strItem, strItemList, strDelimiter) ; 2 strMsgTitle = "Demo: udfItemLocateNC (strItem, strItemList, strDelimiter)" strMsgText = StrCat (strItemList, @LF, strItem, " = ", intResult) Pause (strMsgTitle, strMsgText) :Test21 ; udfItemLocateWild (strPattern, strItemList, strDelimiter) strDelimiter = "," strItemList = "apple,pear,banana,lemon,orange,peach,applesauce,bananashake" strPattern = "ap*" strResultList = udfItemLocateWild (strPattern, strItemList, strDelimiter) ; "apple,applesauce" strMsgTitle = "Demo: udfItemLocateWild (strPattern, strItemList, strDelimiter)" strMsgText = StrCat (strItemList, @LF, strPattern, " = ", strResultList) Pause (strMsgTitle, strMsgText) :Test22 ; udfItemLocateWild (strPattern, strItemList, strDelimiter) strDelimiter = "," strItemList = "apple,pear,banana,lemon,orange,peach,applesauce,bananashake" strPattern = "*an*" strResultList = udfItemLocateWild (strPattern, strItemList, strDelimiter) ; "banana,orange,bananashake" strMsgTitle = "Demo: udfItemLocateWild (strPattern, strItemList, strDelimiter)" strMsgText = StrCat (strItemList, @LF, strPattern, " = ", strResultList) Pause (strMsgTitle, strMsgText) :Test23 ; udfItemLocateWild (strPattern, strItemList, strDelimiter) strDelimiter = "," strItemList = "apple,pear,banana,lemon,orange,peach,applesauce,bananashake" strPattern = "?ea*" strResultList = udfItemLocateWild (strPattern, strItemList, strDelimiter) ; "pear,peach" strMsgTitle = "Demo: udfItemLocateWild (strPattern, strItemList, strDelimiter)" strMsgText = StrCat (strItemList, @LF, strPattern, " = ", strResultList) Pause (strMsgTitle, strMsgText) :Test31 ; udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase) strDelimiter = "," strItemList = "Monday,Sunday,FUNday" strItem = "funday" blnMatchCase = @TRUE strItemResult = udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase) ; "" strMsgTitle = "Demo: udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase)" strMsgText = StrCat (strItemList, @LF, strItem, " = ", strItemResult) Pause (strMsgTitle, strMsgText) :Test32 ; udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase) strDelimiter = "," strItemList = "Monday,Sunday,FUNday" strItem = "funday" blnMatchCase = @FALSE strItemResult = udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase) ; "FUNday" strMsgTitle = "Demo: udfItemFetch (strItem, strItemList, strDelimiter, blnMatchCase)" strMsgText = StrCat (strItemList, @LF, strItem, " = ", strItemResult) Pause (strMsgTitle, strMsgText) Exit