extract Method

Class: ByteString

Description

This method extracts a portion of a ByteString based on a specified first and last byte position to extract.

 

Because both the first and the last position are expressed as byte offsets, the resulting substring may no longer represent a valid character String, even if the source did represent a valid String (e.g. as obtained by String.toByteString()). Either the first or the last character of the source may have been "cut in halves".

 

Use ByteString.extract() if you want a sequence of bytes with exactly to-from +1 bytes (assuming from>0 and to'>byteString.length(). If you want to be sure that substrings are character aligned consider using String.extract() or String.byteLimitSubstring().

Syntax

ByteString.extract(Number from,Number to)

Parameters

from

The first byte in the string to extract. The default is 1.

to

The last byte in the string to extract. The default is the value in the from parameter.

Returns

A ByteString that is a substring of the source ByteString.

When Became Available

Profile V7.0

Example #1

type RecordCIFSIG cifsig = Db.getRecord("CIFSIG","ACN=:ACN")

type ByteString SIG = cifsig.sig.toByteString()

type ByteString CHUNK = SIG.extract(1,450)

*ACN must be defined prior to the getRecord statement

Example #2

type String     STR = "Knäckebröd"

type ByteString BST = STR.toByteString()

//

// get first three byres (cuts the ä in halves)

type ByteString XTR = BST.extract(1,3)

type String ERROR = {String}XTR // may throw runtime exception !!