コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
strings.trim
strings.trim(string_to_trim, cutset)
説明
指定された文字列の先頭と末尾の空白を削除します。また、入力文字列から不要な文字(cutset 引数で指定)を削除します。
パラメータのデータ型
STRING
、STRING
戻り値の型
STRING
コードサンプル
ユースケースの例を次に示します。
例 1
次の例では、同じ文字列が入力文字列とカットセットとして渡されるため、空の文字列が返されます。
strings.trim("str", "str") // ""
例 2
次の例では、カットセットとして空の文字列が渡されます。カットセットで削除する文字が指定されていないため、元の文字列 str が返されます。
strings.trim("str", "") = "str"
例 3
次の例では、入力文字列がすでに空で、削除する文字がないため、関数は空の文字列を返します。
strings.trim("", "str") = ""
例 4
次の例では、trim 関数が次のものを削除するため、関数は str を返します。
- 「a aastraa aa 」の末尾に空白文字が含まれている
- カットセットで指定された文字(スペース、a)
strings.trim("a aastraa aa ", " a") = "str"
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-29 UTC。
[[["わかりやすい","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 UTC。"],[[["\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\""]]