ByteArrayToString

ByteArrayToString[ba]

returns a string by decoding the data in the byte array ba, assuming UTF-8 encoding.

ByteArrayToString[ba,"encoding"]

interprets the data in the specified character encoding.

Details

Examples

open allclose all

Basic Examples  (2)

Create a string from a ByteArray, assuming it contains UTF-8 data:

Create a string from a ByteArray, interpreting the data as ISO 8859-7 Latin/Greek:

Scope  (2)

Convert ASCII bytes of English capital letters to a string:

Compare different character encodings:

Applications  (1)

Import a webpage:

Extract the bytes of the page in a ByteArray object:

Convert the UTF-8 encoded data to a string:

Display the first five lines of the raw page:

Properties & Relations  (4)

All bytes can be represented in ISO8859-1:

The characters produced in this encoding have code points 0 to 255:

The length of the string generated is less than or equal to the length of the byte array:

ByteArrayToString[str] decodes UTF-8 bytes to a string representation:

FromCharacterCode[bytes] converts code points to a string:

ByteArrayToString is the inverse of StringToByteArray:

Possible Issues  (1)

Not all byte sequences are valid UTF-8 codes:

Invalid bytesin this case 162are interpreted as literal code points:

Converting the string back to a byte array produces a different but valid UTF-8 byte sequence:

Introduced in 2017
 (11.2)