Function: text.encode Stay organized with collections Save and categorize content based on your preferences.
Encodes given text to bytes, using the specified character set.
Arguments
| Arguments | |
|---|---|
text |
The input to be encoded. |
charset |
The IANA charset name; e.g. |
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)}
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.