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  (5)

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:

An empty byte array produces an empty string:

An empty list is accepted as a synonym for an empty 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:

Wolfram Research (2017), ByteArrayToString, Wolfram Language function, https://reference.wolfram.com/language/ref/ByteArrayToString.html.

Text

Wolfram Research (2017), ByteArrayToString, Wolfram Language function, https://reference.wolfram.com/language/ref/ByteArrayToString.html.

CMS

Wolfram Language. 2017. "ByteArrayToString." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ByteArrayToString.html.

APA

Wolfram Language. (2017). ByteArrayToString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ByteArrayToString.html

BibTeX

@misc{reference.wolfram_2023_bytearraytostring, author="Wolfram Research", title="{ByteArrayToString}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/ByteArrayToString.html}", note=[Accessed: 20-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_bytearraytostring, organization={Wolfram Research}, title={ByteArrayToString}, year={2017}, url={https://reference.wolfram.com/language/ref/ByteArrayToString.html}, note=[Accessed: 20-April-2024 ]}