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.
ByteArrayToString
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
- In ByteArrayToString[ba,…], ba should be a ByteArray object.
- The value of "encoding" can be any member of $CharacterEncodings.
Examples
open all close allBasic Examples (2)
Create a string from a ByteArray, assuming it contains UTF-8 data:
ByteArray[{97, 65, 206, 177}]ByteArrayToString[%]Create a string from a ByteArray, interpreting the data as ISO 8859-7 Latin/Greek:
ByteArray[{97, 65, 225}]ByteArrayToString[%, "ISO8859-7"]Scope (2)
Convert ASCII bytes of English capital letters to a string:
ascii = ByteArray[RandomInteger[ToCharacterCode["AZ"], 10]]ByteArrayToString[ascii]Compare different character encodings:
highRange = ByteArray[Range[191, 200]]ByteArrayToString[highRange, "ISO8859-1"]ByteArrayToString[highRange, "ISO8859-5"]Applications (1)
data = URLRead["mbl.is"]Extract the bytes of the page in a ByteArray object:
bytes = data["BodyByteArray"]Convert the UTF-8 encoded data to a string:
str = ByteArrayToString[bytes];Display the first five lines of the raw page:
Snippet[str, 5]Properties & Relations (5)
All bytes can be represented in ISO8859-1:
ba = ByteArray[Range[0, 255]]ByteArrayToString[ba, "ISO8859-1"]//InputFormThe characters produced in this encoding have code points 0 to 255:
ToCharacterCode[%] == Range[0, 255]The length of the string generated is less than or equal to the length of the byte array:
ba = ByteArray[{215, 169, 215, 156, 215, 149, 215, 157, 32, 104, 101, 108, 108, 111}]StringLength[ByteArrayToString[ba]]StringLength[ByteArrayToString[ba, "ISO8859-8"]]An empty byte array produces an empty string:
ByteArrayToString[ByteArray[{}]]//InputFormAn empty list is accepted as a synonym for an empty byte array:
ByteArrayToString[{}]//InputFormByteArrayToString[str] decodes UTF-8 bytes to a string representation:
bl = {195, 139, 65, 195, 146, 75, 195, 135, 120, 195, 129, 115, 195, 137, 93};
ba = ByteArray[bl];
ByteArrayToString[ByteArray[ba]]FromCharacterCode[bytes] converts code points to a string:
FromCharacterCode[bl]ByteArrayToString is the inverse of StringToByteArray:
str = "I will round trip";
str == ByteArrayToString[StringToByteArray[str]]Possible Issues (1)
Not all byte sequences are valid UTF-8 codes:
str = ByteArrayToString[ByteArray[{126, 162, 195, 136}]]Invalid bytes—in this case 162—are interpreted as literal code points:
ToCharacterCode[str]Converting the string back to a byte array produces a different but valid UTF-8 byte sequence:
StringToByteArray[str]//NormalRelated Guides
History
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_2026_bytearraytostring, author="Wolfram Research", title="{ByteArrayToString}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/ByteArrayToString.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_bytearraytostring, organization={Wolfram Research}, title={ByteArrayToString}, year={2017}, url={https://reference.wolfram.com/language/ref/ByteArrayToString.html}, note=[Accessed: 15-June-2026]}