textEncode(text, [encoding]) Last updated: 04. Mar 2025
Converts a string into bytes using the specified encoding.
Parameters
Name | Type | Description |
---|---|---|
text | string | |
encoding (optional) | string | Default is UTF8 |
Returns
A byte array.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.// Encoding a string into bytes
let bytes = docly.textEncode("Hello, docly!", "utf8");
console.log(bytes); // Outputs byte array
// Decoding bytes back into a string
let str = docly.textDecode(bytes, "utf8");
console.log(str); // Outputs: Hello, docly!