$bfind

From Scriptwiki
Revision as of 12:41, 11 April 2007 by Cail (talk | contribs) (moved from commands -> text and number identifiers)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The $bfind identifier is used to find a matching value in a binary file.

$bfind(&binvar,N,M)

Returns the position of the first matching character.

N is the starting position for the search.

M is the matchtext, it can contain plain text or ascii values. The search is case-insensitive.

use $bfind().text to force a plain text search, in case your text is a number.

Examples

bset -t &test 1 ABC 97 abcd
echo -a $bvar(&test,1,$bvar(&test,0)) returns 65 66 67 32 57 55 32 97 98 99 1000
echo -a $bfind(&test,1,a)

We searched for an "a", but as the match is case-insensitive, the A matches too. The last echo will echo 1 as an "a" is at position 1.

bset -t &test 1 ABC 97 abcd
echo -a $bfind(&test,1,97) returns 8
echo -a $bfind(&test,1,abcd) returns 8
echo -a $bfind(&test,4,a) returns 8

In the first echo, we only search for character 97, wich is an "a", but this time "A" won't match. In the second echo, we search for "abcd", wich is only found at the end of the var. In the third echo, we search for "a", but we start searching at position 4, so the "A" won't be found.

bset -t &test 1 ABC 97 abcd
echo -a $bfind(&test,1,97).text returns 5

We now searched for the text "97" and not character 97.