使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
cast.as_string
cast.as_string(int_or_bytes_or_bool, optional_default_string)
说明
cast.as_string
函数将 INT
、BYTES
或 BOOL
值转换为其字符串表示形式。您可以提供可选的 default_string
实参来处理转换失败的情况。如果您省略 default_string
实参,或者输入无效的 UTF-8
或 BASE64
字节序列,该函数会返回一个空字符串。
形参数据类型
INT|BYTES|BOOL
,STRING
返回类型
STRING
代码示例
整数到字符串的转换
该函数将整数 123
转换为字符串 "123"
。
cast.as_string(123) = "123"
浮点数到字符串的转换
该函数将浮点数 2.25
转换为字符串 "2.25"
。
cast.as_string(2.25) = "2.25"
字节到字符串转换
该函数将原始二进制 b'01
转换为字符串 "\x01"
。
cast.as_string(b'01, "") = "\x01"
布尔值到字符串的转换
该函数将布尔值 true
转换为字符串 "true"
。
cast.as_string(true, "") = "true"
转化失败(默认为可选提供的字符串)
如果提供的值无效,该函数会默认使用字符串 "casting error"
。
cast.as_string(9223372036854775808, "casting error") = "casting error"
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-29。"],[],[],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\""]]