Core Function BinaryContains

From Sputnik Wiki
Jump to: navigation, search
BinaryContains( <binary-array>, <needle>, <start>, <length> )

Contents

Description

Check if a binary variable contains a given byte or contains another binary variable .

Parameters

binary-array

The binary variable to use.

needle

A binary variable to find or a value to use as a byte

start

Position to start from.

If the start is a negative value the position will work backwards from the length of the binary.

length

Optional; How many bytes to count to before stopping the search.

Default is all remaining bytes;

If length is given and is negative, then that many bytes will be omitted from the end of binary (after the start position has been calculated when a start is negative).

If start denotes the position of this truncation or beyond, empty binary variable will be returned.

Return Value

Success: Returns true.

Failure: Returns false (On error or if there was no bytes were added).

Remarks

None.

Example

// Convert a string to binary
my $bin = Pack("A*", "Hello World!");
// Search for single chars
say BinaryContains($bin, @'A'); // false
say BinaryContains($bin, @'W'); // true
say BinaryContains($bin, @' '); // true
say BinaryContains($bin, @'@'); // false
say BinaryContains($bin, @'!'); // true
// Search for single bytes
say BinaryContains($bin, 0x20); // true
say BinaryContains($bin, 0x7F); // false
// Search for binary
say BinaryContains($bin, Pack("A*", "World")); // true
say BinaryContains($bin, Pack("A*", "Cat")); // false
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox