Stay organized with collections
Save and categorize content based on your preferences.
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"
Float to String Conversion
The function converts the float 2.25
to the string "2.25"
.
cast.as_string(2.25) = "2.25"
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"
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-14 UTC.
[[["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-07-14 UTC."],[],[],null,["### cast.as_string\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n cast.as_string(int_or_bytes_or_bool, optional_default_string)\n\n#### Description\n\nThe `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.\n\n#### Param data types\n\n`INT|BYTES|BOOL`, `STRING`\n\n#### Return type\n\n`STRING`\n\n#### Code samples\n\n##### Integer to String Conversion\n\nThe function converts the integer `123` to the string `\"123\"`. \n\n cast.as_string(123) = \"123\"\n\n##### Float to String Conversion\n\nThe function converts the float `2.25` to the string `\"2.25\"`. \n\n cast.as_string(2.25) = \"2.25\"\n\n##### Bytes to String Conversion\n\nThe function converts the raw binary `b'01` to the string `\"\\x01\"`. \n\n cast.as_string(b'01, \"\") = \"\\x01\"\n\n##### Boolean to String Conversion\n\nThe function converts the boolean `true` to the string `\"true\"`. \n\n cast.as_string(true, \"\") = \"true\"\n\n##### Failed Conversion (Defaults to the Optionally Provided String)\n\nThe function defaults to the string `\"casting error\"` when the value provided is invalid. \n\n cast.as_string(9223372036854775808, \"casting error\") = \"casting error\""]]