OpenBI Docs Buy

Text.FromBinary

Bytes read as text in an encoding, UTF-8 unless you say otherwise.

Group: Text and characters. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Text.FromBinary(binary as nullable binary, optional encoding as nullable number) as nullable text
ParameterTypeDescription
binarynullable binaryThe bytes to read, such as a file's contents.
encodingnullable number
optional
The text encoding: TextEncoding.Utf8 (the default), TextEncoding.Utf16 or TextEncoding.Unicode (UTF-16, little end first), TextEncoding.BigEndianUnicode, TextEncoding.Windows (code page 1252), TextEncoding.Ascii, or a code page's number, such as 1250 for Central European.

Returns

nullable text. The text the bytes hold; null when the binary is null.

Remarks

  • Older files from Windows programs are often in code page 1252: name TextEncoding.Windows for them, or letters such as ø come out wrong.
  • A Unicode byte order mark at the start is left out of the text. With no encoding given, the mark decides the encoding; with a Unicode encoding given, another encoding's mark is an error.
  • Bytes that aren't valid UTF-8 come out as the replacement character �.
  • Every code page of one byte per character is read and written, and UTF-8, UTF-16 and UTF-32. Of the code pages that take several bytes for a character, such as Japanese Shift-JIS (932), OpenBI handles only the plain ASCII text, and says so when there is more.

Compared with Power Query

Known difference in OpenBI Studio 0.3.79, found while this page was written and run on its engine:

  • Text.FromBinary(#binary({147, 140, 139, 158}), 932): Power Query gives "東京" (Shift-JIS). OpenBI reads only the ASCII text of the code pages that take several bytes for a character, and raises an error that says so.

Examples

There and back

Text.FromBinary(Text.ToBinary("Smørbrød"))
"Smørbrød"

Bytes in Windows 1252

In this encoding ø is the single byte 248.

Text.FromBinary(#binary({83, 109, 248, 114}), TextEncoding.Windows)
"Smør"

UTF-16 from another system

Two bytes for each letter, the low byte first.

Text.FromBinary(#binary({79, 0, 115, 0, 108, 0, 111, 0}), TextEncoding.Unicode)
"Oslo"

Text.ToBinary, Lines.FromBinary, Binary.FromText, File.Contents.

Last updated · OpenBI Studio 0.3.79