BinaryIndex

Searches a buffer for a string. (case sensitive)

Syntax:

BinaryIndex ( handle, offset, string, direction)

Parameters:

(i) handle: handle of buffer.

(i) offset: zero-based offset in the buffer to begin search.

(s) string: the string to search for within the buffer.

(i) direction: the search direction. @FWDSCAN searches forwards, while @BACKSCAN searches backwards.

Returns:

(i) offset: offset of string within the buffer, or 0 if not found.

 

This function searches for a string within a buffer. Starting at the offset position, it goes forwards or backwards depending on the value of the direction parameter. It stops when it finds the string within the buffer and returns the string's beginning offset.

Notes: BinaryIndex has been superceded with the function BinaryIndexEx.

The string parameter may be composed of any characters except the null (00) character. A blank string ("") can be specified for the "string" parameter, in which case the function will return the offset of the first non-NULL character found, starting at "offset".

The return value of this function is possibly ambiguous. A zero return value may mean the string was not found, or it may mean the string was found starting at offset 0. If there is a possibility that the string to be searched for could begin at the beginning of the buffer, you must determine some other way of resolving the ambiguity, such as using BinaryPeekStr.

The string being searched for has to appear in the file 'as is'. In some files, such as word processing documents or spreedsheets the string you see in the application may not exist in searchable form in the file.

This function does not support Unicode files.

Note: This function performs a linear search so performance may be affected by very large binary buffers available to 64-bit WinBatch.

 

Example:


; Find line number of line in config.sys where HIMEM occurs
fs1 = FileSize( "C:\CONFIG.SYS" )
binbuf1 = BinaryAlloc( fs1 )
a1 = BinaryRead( binbuf1, "C:\CONFIG.SYS" )
a = BinaryIndex( binbuf1, 0, "HIMEM", @FWDSCAN ) ; find HIMEM
If a == 0
   Message("Hmmm", "HIMEM not found in CONFIG.SYS file")
Else
   c = BinaryStrCnt( binbuf1, 0, a, @CRLF) + 1
   Message("Hmmm", "HIMEM found on line %c%")
EndIf
See Also:

Binary Operations, BinaryCopy, BinaryIndexBin, BinaryIndexEx, BinaryIndexNc BinaryEodGet, BinaryEodSet, BinaryStrCnt