WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

String Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

udfStringsExist

 Keywords: search find check exist existance sub-string string array binary buffer fast 

;--------------------------------------------------------------------------------;
;udfStringsExist : checks the existance of a sub-string(s) with in another string ;
;                                                                                ;
;--------------------------------------------------------------------------------;
;mainstring      : the string to search for the sub-string.                      ;
;arrayofstrings  : and array of string to search for                             ;
;                                                                                 ;
;--------------------------------------------------------------------------------;
;returns         : @true if any one sub-string exists in the string,             ;
;                  @false if non of the sub-string(s) exist in the string         ;
;--------------------------------------------------------------------------------;
;                                                                                 ;
;--------------------------------------------------------------------------------;

#DefineFunction udfStringsExist(mainstring, arrayofstrings)
   retval = 0
   ; load string into binary buffer
   bb = BinaryAlloc( StrByteCount( mainstring, -1 ) )
   BinaryPokeStr(bb, 0, mainstring)
   ; loop through each string in the array and search the binary buffer
   For xx = 0 To ArrInfo(arrayofstrings, 1 )-1
       str = arrayofstrings[xx]
       ;retval = BinaryIndex( bb, 0, str, @Fwdscan ) ;search for string
       retval = BinaryIndexEx(bb, 0, str, @FWDSCAN, 0 )       ;search for string (not case sensitive)
       If retval != -1
          retval = @TRUE ; if found force @true
          Break ; return immediately
        EndIf
   Next
   ; free binary buffer
   BinaryFree(bb)
   If retval == -1 Then retval = 0 ; if not found force @false
   Return retval
#EndFunction

mainstring = '0123456789abcdefghijklmnopqrstuvwxyz'
lookfor = '- ! @ # $ %% & ^ * ( ) _ +' ; should return 0
lookfor = 'a b c' ; should return 1
lookfor = '0' ; should return 1
lookfor = 'z' ; should return 1

arrayofstrings=Arrayize(lookfor,' ')

result = udfStringsExist(mainstring, arrayofstrings)
Pause('udfStringExist', result)

Article ID:   W18395
Filename:   udfStringsExist .txt
File Created: 2009:09:04:11:58:30
Last Updated: 2009:09:04:11:58:30