Core Function BinaryRemove
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> BinaryRemove( <binary-array>, <start>, <length> ) </pre> === Description === Remove bytes from a binary variable. === Parameters === ==== binary-array ==== The binary ...") |
(→Example) |
||
Line 56: | Line 56: | ||
// Prints: | // Prints: | ||
// Before: | // Before: | ||
− | // 00 | 48 65 6C 6C 6F | + | // 00 | 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World! |
// After: | // After: | ||
// 00 | 48 65 -- -- -- -- -- -- -- -- -- -- -- -- -- -- He | // 00 | 48 65 -- -- -- -- -- -- -- -- -- -- -- -- -- -- He | ||
Line 76: | Line 76: | ||
// Prints: | // Prints: | ||
// Before: | // Before: | ||
− | // 00 | 48 65 6C 6C 6F | + | // 00 | 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World! |
// After: | // After: | ||
// 00 | 48 65 20 57 6F 72 6C 64 21 -- -- -- -- -- -- -- He World! | // 00 | 48 65 20 57 6F 72 6C 64 21 -- -- -- -- -- -- -- He World! | ||
Line 96: | Line 96: | ||
// Prints: | // Prints: | ||
// Before: | // Before: | ||
− | // 00 | 48 65 6C 6C 6F | + | // 00 | 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 -- -- -- -- Hello World! |
// After: | // After: | ||
// 00 | 48 65 6C 6C 6F 20 57 6F 72 -- -- -- -- -- -- -- Hello Wor | // 00 | 48 65 6C 6C 6F 20 57 6F 72 -- -- -- -- -- -- -- Hello Wor |
Revision as of 22:19, 2 August 2014
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