BinaryIndexEx

Searches a buffer for a string. This function is very similar to BinaryIndex and BinaryIndexNc, except this function will return -1, if the specified string was not found.

Syntax:

BinaryIndexEx( handle, offset, string, direction, match-case )

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.

(i) match-case: This function is almost the same as BinaryIndex (if "match-case" = 1) and BinaryIndexNc (if "match-case" =0).

Returns:

(i) offset: offset of string within the buffer, if the specified string is not found, this function returns -1 (unlike BinaryIndex and BinaryIndexNC , which return 0).

 

Note:This function is almost the same as BinaryIndex (if "match-case" = @TRUE) and BinaryIndexNc (if "match-case" = @FALSE). The one difference: if the specified string is not found, this function returns -1 (unlike those other functions, which return 0).

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 = BinaryIndexEx( binbuf1, 0, "HIMEM", @FWDSCAN ,0);find HIMEM
If a == -1
   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, BinaryIndexNc BinaryEodGet, BinaryEodSet, BinaryStrCnt, BinaryIndex