Core Function BinaryRemove
From Sputnik Wiki
BinaryRemove( <binary-array>, <start>, <length> )
Contents |
Description
Remove bytes from a binary variable.
Parameters
binary-array
The binary variable to use.
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 delete.
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 removed).
Remarks
None.
Example
Remove everything after position 2
// Create the binary $a = Pack("A*", "Hello World!"); // Print it say "Before:"; say BinaryExpand($a); // Remove bytes BinaryRemove($a, 2); // Print result say "After:"; say BinaryExpand($a); // Prints: // Before: // 00 | 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World! // After: // 00 | 48 65 -- -- -- -- -- -- -- -- -- -- -- -- -- -- He
Remove 3 bytes after position 2
// Create the binary $a = Pack("A*", "Hello World!"); // Print it say "Before:"; say BinaryExpand($a); // Remove bytes BinaryRemove($a, 2, 3); // Print result say "After:"; say BinaryExpand($a); // Prints: // Before: // 00 | 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World! // After: // 00 | 48 65 20 57 6F 72 6C 64 21 -- -- -- -- -- -- -- He World!
Remove the last 3 bytes
// Create the binary $a = Pack("A*", "Hello World!"); // Print it say "Before:"; say BinaryExpand($a); // Remove bytes BinaryRemove($a, -3); // Print result say "After:"; say BinaryExpand($a); // Prints: // Before: // 00 | 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World! // After: // 00 | 48 65 6C 6C 6F 20 57 6F 72 -- -- -- -- -- -- -- Hello Wor