Text.FromBinary
TextDecodes a binary value into text using the specified encoding.
Syntax
Text.FromBinary(binary as binary, optional encoding as nullable number) as textParameters
| Name | Type | Required | Description |
|---|---|---|---|
binary | binary | Yes | The binary value to decode. |
encoding | number | No | A TextEncoding value specifying the character encoding. Defaults to TextEncoding.Utf8 (65001). Common values: TextEncoding.Ascii (20127), TextEncoding.Unicode (1200), TextEncoding.Utf16 (1200), TextEncoding.Utf8 (65001). |
Return Value
text — A text value decoded from the binary data.
Remarks
Text.FromBinary decodes a binary value into a text string using the specified character encoding. This is the inverse of Text.ToBinary. If no encoding is specified, TextEncoding.Utf8 (65001) is used by default, which is correct for most modern data sources.
The encoding parameter accepts values from the TextEncoding enum:
- TextEncoding.Utf8 (65001) — default; correct for most APIs and modern files
- TextEncoding.Ascii (20127) — 7-bit ASCII only; safe for codes and identifiers
- TextEncoding.Unicode / TextEncoding.Utf16 (1200) — little-endian UTF-16
- TextEncoding.Utf16BE (1201) — big-endian UTF-16
- TextEncoding.Utf32 (12000)
- TextEncoding.Windows (1252) — legacy Windows Western European encoding
Always specify the encoding explicitly when working with binary data from legacy systems or files that may not be UTF-8. Using the wrong encoding will produce garbled output without raising an error, because the bytes are valid but misinterpreted. If you receive binary from a REST API, UTF-8 is almost always correct. For older CSV or text files from Windows systems, TextEncoding.Windows (1252) may be needed.
Text.FromBinary is commonly used after Binary.FromText decodes a base64 payload, or when reading raw binary file content that needs to be treated as text before parsing.
Examples
Example 1: Decode a base64 payload from a web API response
Text.FromBinary(Binary.FromText("SGVsbG8gV29ybGQ=", BinaryEncoding.Base64))Result | |
|---|---|
| 1 | Hello World |
Example 2: Round-trip encode and decode with explicit encoding
let
original = "Alice Smith",
encoded = Text.ToBinary(original, TextEncoding.Utf8),
decoded = Text.FromBinary(encoded, TextEncoding.Utf8)
in
decodedThe final output — decodes the UTF-8 binary back to text using Text.FromBinary with the same encoding, recovering the original string exactly.
Result | |
|---|---|
| 1 | Alice Smith |
Example 3: Decode a Windows-1252 encoded binary file
Text.FromBinary(
Text.ToBinary("Ren\u00e9e Dupont", TextEncoding.Windows),
TextEncoding.Windows
)Result | |
|---|---|
| 1 | Renée Dupont |