"Sputnik" help  
Sputnik Help
BinaryMid(<binary>, <start>, [<end>])

Description

The BinaryMid function is used to extract a portion of a binary string, starting from a specified position (<start>) and optionally ending at another position (<end>). It supports negative values for <start> and <end>, allowing you to specify positions relative to the end of the binary string.

Parameters

<binary> This is the original binary string from which a portion will be extracted.
<start> This parameter determines the starting position of the extraction. If <start> is a positive value, it specifies the index at which the extraction should begin, starting from 0 for the first byte of the binary string. If <start> is a negative value, it indicates the position relative to the end of the binary string. For example, -1 represents the last byte, -2 represents the second-to-last byte, and so on.
<end> Optional parameter specifies the ending position of the extraction. If provided, the extraction will stop before the byte at this position. Similar to <start>, <end> can be a positive or negative value. If not specified, the extraction will continue to the end of the binary string.

Return Value

Success: Returns new binary string that contains the extracted portion of the original binary string.
Failure: Returns an empty binary string.

Remarks

The BinaryMid function allows you to extract a portion of a binary string by specifying the starting and ending positions. The function supports both positive and negative values for the <start> and <end> parameters. Positive values indicate positions relative to the beginning of the binary string, while negative values indicate positions relative to the end of the binary string.

If <start> is a positive value, it represents the index at which the extraction should begin, starting from 0 for the first byte of the binary string. For example, a value of 2 will start the extraction from the third byte of the binary string.

If <start> is a negative value, it indicates the position relative to the end of the binary string. For example, -1 represents the last byte of the binary string, -2 represents the second-to-last byte, and so on.

The <end> parameter is optional. If provided, the extraction will stop before the byte at this position. If not specified, the extraction will continue to the end of the binary string.

It's important to note that the positions specified for <start> and <end> are inclusive, meaning that the byte at the specified positions will be included in the extracted portion.

Related

BinaryMidReplace, BinarySubStr, BinarySubStrReplace

Example

Example of usage:

my $binary = BinaryFromStr("Hello World");
my $result = BinaryMid($binary, 2, -3);
say $result;
// Output: "llo Wor"

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org