BinaryReplace

Replaces strings in a binary buffer.

Syntax:

BinaryReplace( handle, search-string, replacement-string, match-case )

Parameters:

(i) handle:  handle of buffer.

(s) search-string: specifies the string to be replaced. Specify a blank string ("") to indicate that the search string is a NULL character.

(s) replacement-string: specifies the string with which "search-string" will be replaced. Specify a blank string ("") to indicate that "search-string" should be removed and not replaced with anything.

(i) match-case: @TRUE to indicate that "search-string" is case- sensitive, or @FALSE if case should be ignored.

Returns:

(i) number of occurrences of "search-string" that were replaced.

 

This function searches a binary buffer, and replaces all occurrences of "search-string" with "replacement-string". Each time an occurrence of "search-string" is replaced, processing continues right after the replacement string that was inserted in its place. If "replacement-string" is longer than "search-string", the binary buffer must be large enough for all the new strings to fit.

Note: This function uses a temporary buffer that can be of greater size than the passed in buffer. This means that the function may need twice or more the virtual memory used by the passed in buffer.

Example:


str="hello"
rep="goodbye"
dafile="C:\Temp\myfile.txt"
fs = FileSize( dafile )
binbuf = BinaryAlloc( fs+100 )
ret = BinaryRead( binbuf, dafile )
num = BinaryReplace( binbuf, str, rep ,0)
Message( "Number of '%str%' strings replaced", num )
BinaryWrite( binbuf, dafile )
BinaryFree( binbuf)
Exit
See Also:

BinaryAlloc, BinaryIndexEx, BinaryIndexNC