Loading

SUBSTRING


strings binary
Since v1.0.0
Available on all platforms

Extract a substring from a STRING input, or a subarray from a BYTE ARRAY input.
If the length is ommitted, it extracts until the end of the string or byte array. If length is greater than max length, extract stops at the input end.

If the start is greater than the input size, SUBSTRING raises an error.

Since 2.1, the start index can be negative. In this case the effective index is index + size of the STRING.

Signature

Examples

'0123456789ABCDEF' 3 SUBSTRING '0123456789ABCDEF' 3 4 SUBSTRING 'abcdef' 'UTF-8' ->BYTES 3 3 SUBSTRING 'UTF-8' BYTES->
// raw payload 'FF4201FFFE8B' HEX-> 'rx' STORE //extract the temperature sensor (32.2 °C), //encoded on byte 1 and 2 (4201) with a reverse endianness $rx 1 2 SUBSTRING //extract [ 0x42 0x01 ] REVERSE //reverse endianness [ 0x01 0x42 ] TOLONG 0.1 * //convert to long, multiply by 0.1 (32.2) //then extract the pressure sensor (-3.73 bar) //encoded on byte 3 to 5 (24 bits) (FFFE8B) $rx 3 3 SUBSTRING //extract [ 0xFF 0xFE 0x8B ] TOLONG 0.01 * //convert to long, multiply by 0.01 (-3.73)