BinaryStrCnt

Counts the occurrences of a string in some or all of a binary buffer.

Syntax:

BinaryStrCnt( handle, start-offset, end-offset, string )

Parameters:

(i) handle: handle of buffer.

(i) start-offset: zero-based offset for start of search.

(i) end-offset: zero-based offset for end of search.

(s) string: case sensitive string to search for.

Returns:

(i)  number of occurrences of string found.

 

This function will search all or a portion of a binary buffer for a string and will return a count of the occurrences of the string found. The buffer will be searched from the start-offset to the end-offset.

Note: The string parameter may be composed of any characters except the null (00) character. This function cannot process a null character.

 

Example:


; Find number of Device, DEVICE= and device= lines in config.sys
fs1 = FileSize( "C:\CONFIG.SYS" )
binbuf1 = BinaryAlloc( fs1 )
BinaryRead( binbuf1, "C:\CONFIG.SYS" )
a = BinaryStrCnt( binbuf1, 0, fs1 - 1, "Device=")
b= BinaryStrCnt( binbuf1, 0, fs1 - 1, "DEVICE=")
c= BinaryStrCnt( binbuf1, 0, fs1 - 1, "device=")
BinaryFree( binbuf1 )
d = a + b + c
Message( "Hmmm", "Total Device= lines found in Config.Sys is %d% " )
See Also:

Binary Operations, BinaryEodGet, BinaryEodSet, BinaryIndex, BinaryPeek, BinaryPeekStr, BinaryPoke, BinaryPokeStr