透過集合功能整理內容
你可以依據偏好儲存及分類內容。
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"
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間: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\""]]