8.15.0.12
7.7 Byte Strings🔗ℹ
A byte string is a sequence of bytes. A byte string
works with map-referencing […] to access a byte via
#%index. A byte string also works with the
++ operator to append bytes strings. A byte string can be used
as sequence, in which case it supplies its bytes in order.
A byte string is normally mutable, but byte-string literals are
immutable. The Bytes annotation is satisfied by both
mutable and immutable byte strings, while MutableBytes
and ImmutableBytes require one or the other.
Two byte strings are equal by is_now as long as they have
equal contents, even if one is mutable and the other is immutable.
Byte strings are comparable, which means that generic operations
like < and > work on byte strings.
Matches byte strings, where
MutableBytes matches only
mutable byte strings, and and
ImmutableBytes matches
only immutable byte strings.
Static information associated by Bytes, etc., makes
an expression acceptable as a sequence to for in static mode.
Creates a fresh byte string with length bytes, where each
byte is initialized to byte.
Returns the number of bytes in bstr.
Equivalent to
bstr[n] (with the default implicit
#%index form). Returns the
nth byte of
bstr (starting from
0).
Equivalent to
bstr[n] := byte (with the default implicit
#%index form). Updates the
nth position of
bstr to
byte.
|
|
|
Bytes.copy(#"hbc") |
|
|
Bytes.copy(#"hhc") |
Appends bstrs by creating a new mutable byte string with
all bytes.
Returns the substring of bstr from start (inclusive)
to end (exclusive).
|
Bytes.copy(#"ll") |
|
Bytes.copy(#"llo") |
Returns a fresh mutable byte string with the same initial content as
bstr.
|
|
Bytes.copy(#"apple") |
|
#true |
Copies bytes from
src_bstr at
src_start (inclusive) to
src_end (exclusive) into
dest_bstr starting at
dest_start. The length of
dest_bstr must be at least
dest_start + (src_end - src_start).
Sets every byte in bstr to byte.
Returns an immutable byte string as-is or copies a mutable byte
string’s content to an immutable byte string.
Converts a byte string to a string, decoding as UTF-8, Latin-1, or the
current locale’s encoding. The
err_char argument provides a
character to use in place of an encoding error, where
#false means that an exception is thrown.