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.
annotation | |
| |
annotation | |
| |
annotation | |
Static information associated by Bytes, etc., makes an expression acceptable as a sequence to for in static mode.
function | ||
> Bytes.make(5, Byte#"!")
Bytes.copy(#"!!!!!")
5
> Bytes.length(#"hello")
5
> #"abc"[0]
97
97
> b
Bytes.copy(#"hbc")
> b
Bytes.copy(#"hhc")
method | |
| |
| |
function | |
|
Bytes.copy(#"abcdefghi")
method | |||
| |||
method | |||
When given one argument, rge is used to derive start and end as in String.substring.
Bytes.copy(#"ll")
Bytes.copy(#"llo")
Bytes.copy(#"llo")
Bytes.copy(#"hell")
Bytes.copy(#"hello")
Bytes.copy(#"apple")
#true
function | ||||||
|
method | |
|
> b
Bytes.copy(#"xxxxx")
method | |||||
| |||||
| |||||
method | |||||
| |||||
| |||||
method | |||||
|
> #"hello".utf8_string()
"hello"