main-apidocs-erlang-estdlib-binary.md
An implementation of a subset of the Erlang/OTP binary interface.
| at/2 | Get a byte from a binary by index. |
| copy/1 | Returns a copy of the binary. |
| copy/2 | Returns a binary containing N copies of the input binary. |
| decode_hex/1 | Decodes a hex encoded binary into a binary. |
| encode_hex/1 | Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits "a" to "f". |
| encode_hex/2 | Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits "a" to "f". |
| list_to_bin/1 | Works exactly as erlang:list_to_binary/1. |
| longest_common_prefix/1 | Returns the length of the longest common prefix of the binaries in the list. |
| match/2 | Find the first occurrence of Pattern in Binary. |
| match/3 | Find the first occurrence of Pattern in Binary. |
| part/3 | Get the part of a given binary. |
| replace/3 | Replaces first occurrence of Pattern in Binary with Replacement. |
| replace/4 | Replaces occurrences of Pattern in Binary with Replacement. |
| split/2 | Split a binary according to pattern. |
| split/3 | Split a binary according to pattern. |
at(Binary::binary(), Index::non_neg_integer()) -> byte()
Binary: binary to get a byte from
Index: 0-based index of the byte to return
returns: value of the byte from the binary
Get a byte from a binary by index.
copy(Binary::binary()) -> binary()
Binary: binary to copy
returns: a copy of the binary
Returns a copy of the binary.
copy(Binary::binary(), N::non_neg_integer()) -> binary()
Binary: binary to copy
N: number of times to copy the binary
returns: a binary containing N copies of the input binary
Returns a binary containing N copies of the input binary.
decode_hex(Data::<<_:_*16>>) -> binary()
Data: hex encoded binary to decode
returns: decoded binary
Decodes a hex encoded binary into a binary.
encode_hex(Data::binary()) -> binary()
Data: binary data to convert into hex encoded binary
returns: hex encoded binary
Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits “a” to “f”.
encode_hex(Data::binary(), Case::lowercase | uppercase) -> binary()
Data: binary data to convert into hex encoded binary
Case: which case to encode into
returns: hex encoded binary
Encodes a binary into a hex encoded binary using the specified case for the hexadecimal digits “a” to “f”.
list_to_bin(ByteList::iolist()) -> binary()
ByteList: iolist to convert to binary
returns: binary representation of ByteList
Works exactly as erlang:list_to_binary/1. This function is provided for completeness.
longest_common_prefix(Binaries::[binary(), ...]) -> non_neg_integer()
Binaries: non-empty list of binaries
returns: length of the longest common prefix of all binaries in the list
Returns the length of the longest common prefix of the binaries in the list.
match(Binary::binary(), Pattern::binary() | [binary()]) -> {non_neg_integer(), non_neg_integer()} | nomatch
Binary: binary to search in
Pattern: pattern to search for
returns: {Start, Length} or nomatch
Equivalent to match(Binary, Pattern, []).
Find the first occurrence of Pattern in Binary.
match(Binary::binary(), Pattern::binary() | [binary()], Options::[term()]) -> {non_neg_integer(), non_neg_integer()} | nomatch
Binary: binary to search in
Pattern: pattern to search for
Options: options for the match
returns: {Start, Length} or nomatch
Find the first occurrence of Pattern in Binary. Options can include {scope, {Start, Length}}.
part(Binary::binary(), Pos::non_neg_integer(), Len::integer()) -> binary()
Binary: binary to extract a subbinary from
Pos: 0-based index of the subbinary to extract
Len: length, in bytes, of the subbinary to extract.
returns: a subbinary from Binary
Get the part of a given binary. A negative length can be passed to count bytes backwards.
replace(Binary::binary(), Pattern::binary(), Replacement::binary()) -> binary()
Binary: binary where the replacements should occur
Pattern: binary pattern which is to be replaced
Replacement: binary which will replace the pattern
returns: resulting binary after replacements
Equivalent to replace(Binary, Pattern, Replacement, []).
Replaces first occurrence of Pattern in Binary with Replacement. If Pattern is not found, returns the original binary unchanged. Pattern and Replacement must be binaries.
replace(Binary::binary(), Pattern::binary(), Replacement::binary(), Options::[global] | []) -> binary()
Binary: binary where the replacements should occur
Pattern: binary pattern which is to be replaced
Replacement: binary which will replace the pattern
Options: list of options for the replacement operations.
returns: resulting binary after replacements
Replaces occurrences of Pattern in Binary with Replacement. If Options includes global, replaces all occurrences; otherwise, replaces just the first occurrence. If Pattern is not found, returns the original binary unchanged. Pattern and Replacement must be binaries. Only implemented option is global.
split(Binary::binary(), Pattern::binary() | [binary(), ...]) -> [binary()]
Binary: binary to split
Pattern: pattern to perform the split
returns: a list of binaries
Equivalent to split(Binary, Pattern, []).
Split a binary according to pattern. If pattern is not found, returns a singleton list with the passed binary.
split(Binary::binary(), Pattern::binary() | [binary(), ...], Option::[global | trim | trim_all]) -> [binary()]
Binary: binary to split
Pattern: pattern to perform the split
returns: a list of binaries
Split a binary according to pattern. If pattern is not found, returns a singleton list with the passed binary. Pattern can be a binary or a non-empty list of non-empty binaries. Implemented options are global, trim, and trim_all.