TextEncode(text, [encoding]) Last updated: 13. Nov 2023

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!