透過集合功能整理內容
你可以依據偏好儲存及分類內容。
strings.trim
strings.trim(string_to_trim, cutset)
說明
從指定字串中移除前置和後置空格。此外,也會從輸入字串中移除不需要的字元 (由 cutset 引數指定)。
參數資料類型
STRING
、STRING
傳回類型
STRING
程式碼範例
以下是應用範例。
範例 1
在下列範例中,系統會將同一個字串當做輸入字串和 cutset 傳遞,因此會產生空字串。
strings.trim("str", "str") // ""
範例 2
在下列範例中,系統會將空字串當做 cutset 傳遞,因此會產生原始字串 str,因為 cutset 中未指定要移除的字元。
strings.trim("str", "") = "str"
範例 3
在下列範例中,函式會產生空字串,因為輸入字串已為空白,且沒有要移除的字元。
strings.trim("", "str") = ""
範例 4
在下列範例中,函式會產生 str,因為 trim 函式會移除下列項目:
- 「a aastraa aa 」中的尾端空白字元
- cutset 中指定的字元 (空格、a)
strings.trim("a aastraa aa ", " a") = "str"
除非另有註明,否則本頁面中的內容是採用創用 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 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003estrings.trim\u003c/code\u003e removes leading and trailing whitespace from a string, as well as specified characters within the string.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecutset\u003c/code\u003e parameter defines the characters to be removed from the input string in the \u003ccode\u003estrings.trim\u003c/code\u003e function.\u003c/p\u003e\n"],["\u003cp\u003eIf the \u003ccode\u003ecutset\u003c/code\u003e contains all the characters of the \u003ccode\u003estring_to_trim\u003c/code\u003e, the function returns an empty string.\u003c/p\u003e\n"],["\u003cp\u003eWhen the \u003ccode\u003ecutset\u003c/code\u003e is an empty string, nothing is trimmed, and the original string is returned.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estrings.trim\u003c/code\u003e is available for use in both Chronicle Rules and Search.\u003c/p\u003e\n"]]],[],null,["### strings.trim\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n strings.trim(string_to_trim, cutset)\n\n#### Description\n\nTrims leading and trailing white spaces from a given string. Also, remove unwanted characters (specified by the cutset argument) from the input string.\n\n#### Param data types\n\n`STRING`, `STRING`\n\n#### Return type\n\n`STRING`\n\n#### Code samples\n\nThe following are example use cases.\n\n##### Example 1\n\nIn the following example, the same string is passed as the input string and the cutset, which results in an empty string. \n\n strings.trim(\"str\", \"str\") // \"\"\n\n##### Example 2\n\nIn the following example, an empty string is passed as the cutset, which results in the original string str because there are no characters specified in the cutset to remove. \n\n strings.trim(\"str\", \"\") = \"str\"\n\n##### Example 3\n\nIn the following example, the function yields an empty string because the input string is already empty and there are no characters to remove. \n\n strings.trim(\"\", \"str\") = \"\"\n\n##### Example 4\n\nIn the following example, the function yields str because the trim function removes the following:\n\n- trailing whitespace in \"a aastraa aa \"\n- the characters specified in the cutset (space, a)\n\n strings.trim(\"a aastraa aa \", \" a\") = \"str\""]]