Encodes given text to bytes, using the specified character set.
Arguments
Arguments
text
string
The input to be encoded.
charset
string
The IANA charset name; e.g. UTF-8, US-ASCII, ISO-8859-2. Case-insensitive. Default: UTF-8.
Returns
The encoded bytes.
Raised exceptions
Exceptions
ValueError
If the charset is unsupported, or if the text contains codepoints that are not representable in the specified charset.
Examples
# Return Base64 text "SGVsbG8gV29ybGQ=" using `text.encode` function-assignStep:assign:# Encode string to bytes-encodedBytes:${text.encode("Hello World","UTF-8")}-returnStep:# Encode bytes to Base64 textreturn:${base64.encode(encodedBytes)}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-14 UTC."],[],[]]