BinaryFormat.Text
BinaryReturns a binary format that reads a text value from binary data.
Syntax
BinaryFormat.Text(length as any, optional encoding as nullable number) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
length | any | Yes | The number of bytes to decode, or a binary format that reads the length preceding the text. |
encoding | nullable number | No | The text encoding to use (e.g., TextEncoding.Ascii, TextEncoding.Utf8, TextEncoding.Utf16). If not specified, encoding is detected from Unicode byte order marks, defaulting to UTF-8. |
Return Value
function — A binary format function that reads and decodes a text value from binary data.
Remarks
BinaryFormat.Text returns a binary format that reads a text value by decoding a specified number of bytes from binary data. The length parameter can be:
- A number -- Reads exactly that many bytes and decodes them as text.
- A binary format -- Reads the length from the stream using that format first, then reads and decodes that many bytes of text.
The optional encoding parameter specifies the text encoding. Supported values include TextEncoding.Ascii, TextEncoding.Utf8, TextEncoding.Utf16, TextEncoding.Unicode, and TextEncoding.Windows. If omitted, the encoding is determined from Unicode byte order marks (BOM). If no BOM is present, TextEncoding.Utf8 is used.
Examples
Example 1: Decode a fixed number of bytes as ASCII text
let
binaryData = #binary({65, 66, 67}),
textFormat = BinaryFormat.Text(2, TextEncoding.Ascii)
in
textFormat(binaryData)Example 2: Read length-prefixed text
let
binaryData = #binary({2, 65, 66}),
textFormat = BinaryFormat.Text(
BinaryFormat.Byte,
TextEncoding.Ascii
)
in
textFormat(binaryData)Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks