cast.as_string
cast.as_string(int_or_bytes_or_bool, optional_default_string)
Description
The cast.as_string function transforms an INT, BYTES, or BOOL value into its string representation. You can provide an optional default_string argument to handle cases where the cast fails. If you omit the default_string argument, or if the input is an invalid UTF-8 or BASE64 byte sequence, the function returns an empty string.
Param data types
INT|BYTES|BOOL, STRING
Return type
STRING
Code samples
Integer to String Conversion
The function converts the integer 123 to the string "123".
cast.as_string(123) = "123"
Bytes to String Conversion
The function converts the raw binary b'01 to the string "\x01".
cast.as_string(b'01, "") = "\x01"
Boolean to String Conversion
The function converts the boolean true to the string "true".
cast.as_string(true, "") = "true"
Failed Conversion (Defaults to the Optionally Provided String)
The function defaults to the string "casting error" when the value provided is invalid.
cast.as_string(9223372036854775808, "casting error") = "casting error"