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

Conversion UDFs

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

UDF - BinaryStrCntBin

With the advent of the BinaryIndexBin function that allows a binary buffer to be searched for a binary data, specified either as an ascii-encoded hex string or a binary buffer, an occassional need to be able to count the number of occurances of the binary data has arisen.

Thus this UDF, similar to the existing BinaryStrCnt function that can count the number of occurances of binary data in a binary buffer


#DefineFunction BinaryStrCntBin(bb,startoffset,endoffset,lookfor)
   count=0
   While @TRUE
      startoffset=BinaryIndexBin(bb,startoffset,lookfor,@FWDSCAN,@TRUE)
      If startoffset== -1 Then Break
      startoffset=startoffset+1
      If startoffset > endoffset Then Break
      count=count+1
   EndWhile
   Return(count)
#EndFunction


;Test case

fn="c:\stuff\a.wbt"   ; for the test case this is *this* script
fs=FileSize(fn)
bb=BinaryAlloc(fs)
BinaryRead(bb,fn)

;count number of occurances of "offset" using existing method.
x=BinaryStrCnt(bb,0,fs-1,"offset")

;Setup buffer with search string (could be binary data)
cc=BinaryAlloc(100)
BinaryPokeStr(cc,0,"offset")
;Search for the data with the UDF
y=BinaryStrCntBin(bb,0,fs-1,cc)

BinaryFree(bb)
BinaryFree(cc)
Message("x y",StrCat(x,@CRLF,y))


Article ID:   W16243
File Created: 2004:03:30:15:43:32
Last Updated: 2004:03:30:15:43:32