Main Index : Reference :

memmid()


Description

Creates a new byte array that contains an extract from another byte array, specified by the starting position within the original byte array and the length of the result.

Definition

[bytes] memmid([bytes] mem,[int] pos,[int] len)

Parameters

mem is the original byte array.
pos is the starting position of the extract from mem.
len is the length of the extract. (len >= 0)

Return Value

memmid() returns a byte array containing an extract from mem, starting at position mem and with the length len. If the extract goes outside the original string, for example if len is bigger than the length of the byte array, it will be truncated. This means that the length of the returned byte array doesn't always equal len. The starting position, pos, can be negative.

Remember: The first element of a byte array is at position 0.

Example

// See also the examples for strmid().

// The resulting byte array will be 100 bytes long
// and go from 0x2E to 0x91 (46 to 145).

var i,mem = new(bytes,256);          // Allocates 256 bytes
for (i=0x00;i<=0xFF;i++) mem[i] = i; // Fills the byte array from 0x00 to 0xFF

var result = memmid(mem,0x2E,100);

(a better example is welcome)

See Also

[bytes], memins(), memset(), memadd(), memmem()