We deliver solutions for the AI eraâcombining symbolic computation, data-driven insights and deep technology expertise.
StringToByteArray["string"]
returns a byte array corresponding to the UTF-8 encoding of the specified string.
Details Examplesopen allclose all Basic Examples (2)Convert a string to a ByteArray of its UTF-8 representation:
Convert the bytes to a list of numbers:
Convert a string to a ByteArray of its ISO 8859-7 Latin/Greek representation:
Convert the bytes to a list of numbers:
Scope (2)Convert a generated string to UTF-8:
Compare different character encodings:
For these particular characters, ISO8859-15 is identical to ISO8859-1:
Properties & Relations (7)In UTF-8, the number of bytes equals the length of the string only for all-ASCII strings:
The next 1920 characters each require 2 bytes:
And the remaining 63488 code points each require 3 bytes:
The characters in code points 0 through 255 can be represented in ISO8859-1:
Each character is encoded as a byte containing the code point:
In the UTF-8 encoding, the size of byte array object returned is essentially the size of original string:
StringToByteArray[str] converts each character to a sequence of one or more byte values:
ToCharacterCode[str] returns a list of integer code points:
An empty string produces an empty byte array:
In a given character encoding, StringToByteArray and ToCharacterCode return the same bytes:
The list returned by ToCharacterCode uses several times more memory:
The ByteArray object returned by StringToByteArray uses essentially one byte of memory per value:
The list returned by ToCharacterCode uses several bytes of memory per value:
StringToByteArray is the inverse of ByteArrayToString:
Possible Issues (1)All characters in the string must be representable in the character encoding:
Wolfram Research (2017), StringToByteArray, Wolfram Language function, https://reference.wolfram.com/language/ref/StringToByteArray.html. TextWolfram Research (2017), StringToByteArray, Wolfram Language function, https://reference.wolfram.com/language/ref/StringToByteArray.html.
CMSWolfram Language. 2017. "StringToByteArray." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/StringToByteArray.html.
APAWolfram Language. (2017). StringToByteArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringToByteArray.html
BibTeX@misc{reference.wolfram_2025_stringtobytearray, author="Wolfram Research", title="{StringToByteArray}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/StringToByteArray.html}", note=[Accessed: 12-July-2025 ]}
BibLaTeX@online{reference.wolfram_2025_stringtobytearray, organization={Wolfram Research}, title={StringToByteArray}, year={2017}, url={https://reference.wolfram.com/language/ref/StringToByteArray.html}, note=[Accessed: 12-July-2025 ]}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4