Core Function BinaryCompare
(→Example) |
|||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | BinaryCompare( <binary-array>, < | + | BinaryCompare( <binary-array>, <offset>, <needle, <needleOffset>, <length>, <ignoreCase> ) |
</pre> | </pre> | ||
Line 10: | Line 10: | ||
==== binary-array ==== | ==== binary-array ==== | ||
− | |||
− | |||
− | |||
− | |||
The a binary variable to use. | The a binary variable to use. | ||
Line 22: | Line 18: | ||
If the start is a negative value the byte position will work backwards from the length of the shortest binary variable. | If the start is a negative value the byte position will work backwards from the length of the shortest binary variable. | ||
+ | |||
+ | ==== needle ==== | ||
+ | |||
+ | The a binary variable to be comparing to. | ||
+ | |||
+ | ==== needleOffset ==== | ||
+ | |||
+ | Optional; Start position to begin comparing in the needle. (0 = first byte) | ||
==== length ==== | ==== length ==== | ||
Line 30: | Line 34: | ||
If offset denotes the position of this truncation or beyond, failure will be returned ( -2 ). | If offset denotes the position of this truncation or beyond, failure will be returned ( -2 ). | ||
+ | |||
+ | ==== ignoreCase ==== | ||
+ | |||
+ | Optional; if true the comparison is case-insensitive | ||
=== Return Value === | === Return Value === | ||
Line 43: | Line 51: | ||
=== Remarks === | === Remarks === | ||
− | + | If ignoreCase is true, the result is equivalent to performing a case-sensitive comparison after converting the uppercase ASCII letters A-Z in both binary variables to lowercase. | |
=== Example === | === Example === |
Revision as of 21:04, 27 July 2014
BinaryCompare( <binary-array>, <offset>, <needle, <needleOffset>, <length>, <ignoreCase> )
Contents |
Description
Compare two binary variables.
Parameters
binary-array
The a binary variable to use.
offset
Optional; Start position to begin comparing. (0 = first byte)
If the start is a negative value the byte position will work backwards from the length of the shortest binary variable.
needle
The a binary variable to be comparing to.
needleOffset
Optional; Start position to begin comparing in the needle. (0 = first byte)
length
Optional; Maximal number of bytes to compare. By default the entire remainder of the shortest binary variable.
If length is given and is negative, then the compare will begin with many bytes will be omitted from the end of shortest binary variable (after the offset position has been calculated when a offset is negative).
If offset denotes the position of this truncation or beyond, failure will be returned ( -2 ).
ignoreCase
Optional; if true the comparison is case-insensitive
Return Value
-1 if binary1 is less than binary2
1 if binary1 is greater than binary2
0 if they are equal.
-2 on error
Remarks
If ignoreCase is true, the result is equivalent to performing a case-sensitive comparison after converting the uppercase ASCII letters A-Z in both binary variables to lowercase.
Example
my $Binary1 = Pack("A*", "Hello world!!!"); my $Binary2 = Pack("A*", "Hello world!!!"); If( BinaryCompare($Binary1, $Binary2) == 0 ) { println("Both binary variables contain the same data"); } Else { println("No match"); } println(""); println("Lets try again now now that one was changed"); my $Binary1 = Pack("A*", "Test"); If( BinaryCompare($Binary1, $Binary2) == 0 ) { println("Both binary variables contain the same data"); } Else { println("No match"); }
Check from the 4th byte to the 6th byte
my $Binary1 = Pack("A*", "TheFoXok"); my $Binary2 = Pack("A*", "DatFoXNP"); If( BinaryCompare($Binary1, $Binary2, 3, 3) == 0 ) { println("Both binary variables contain the same data"); } Else { println("No match"); }