Core Function OffsetCalc
OffsetCalc( <size>, <start>, <length> )
Contents |
Description
Calculate the START and LENGTH of an array index.
Parameters
size
The size of the array/string you wish to calculate the start/length from.
start
Optional; The position to start. (0 = first)
OR
If the start is a negative value the position will work backwards from the *size*.
Default: 0
length
Optional; The number to extract. By default the entire remainder.
If count is given and is negative, then that many will be omitted from the *size* (after the start position has been calculated when a start is negative). If start denotes the position of this truncation or beyond, null is returned.
Return Value
Success: A two element array with the following:
[0] = Start position (index) [1] = Length
Failure: NULL
Remarks
It works using same thing SubStr() uses so if start is negative it counts from end and so on etc this allows you to include the same offset calculation for start/length of things that Sputnik does for your own needs.
Example
my $Str = "UberFoX"; my $diff = OffsetCalc(StrLen($Str), -3, 3); say SubStr($Str, $diff[0], $diff[1]); // PRINTS // FoX