7.3 Byte Strings

Module ByteString provides an interface to a more economical representation for textual data: a simple array of bytes. In terms of memory, the economy is at least a factor of 8, which may improve local processing, IO, pickle sizes, and remote communications (distributed processing). However strings, i. e., lists, are often more convenient for all forms of recursive processing (e. g., Map or Filter). Typically, you will be processing textual data in list form, but saving or communicating it in byte string form.


{ByteString.is +X ?B}

tests whether X is a byte string.


{ByteString.make +V ?ByteString}

returns a new byte string created from the virtual string V.


{ByteString.get +ByteString +I ?C}

retrieves the Ith character of byte string ByteString. The first index is 0.


{ByteString.append +ByteString1 +ByteString2 ?ByteString3}

returns the new byte string ByteString3 which is the concatenation of ByteString1 and ByteString2.


{ByteString.slice +ByteString1 +FromI +ToI ?ByteString2}

returns a new byte string for the bytes in ByteString1 starting at index FromI and extending up to, but not including, index ToI.


{ByteString.width +ByteString ?I}

{ByteString.length +ByteString ?I}

returns the width I of ByteString.


{ByteString.toString +ByteString ?S}

converts ByteString to a string S.


{ByteString.toStringWithTail +ByteString X ?S}

converts ByteString to a string S ending with X. This is useful for subsequently instantiating X, e. g., with another call to ByteString.toStringWithTail.


{ByteString.strchr +ByteString +OffsetI +Char ?PosBI}

returns the position PosI of the first occurrence of Char in ByteString starting at offset OffsetI. If none is found false is returned instead.

Denys Duchier, Leif Kornstaedt and Christian Schulte
Version 1.4.0 (20080702)