Stay organized with collections
Save and categorize content based on your preferences.
strings.trim
strings.trim(string_to_trim, cutset)
Description
Trims leading and trailing white spaces from a given string. Also, remove unwanted characters (specified by the cutset argument) from the input string.
Param data types
STRING
, STRING
Return type
STRING
Code samples
The following are example use cases.
Example 1
In the following example, the same string is passed as the input string and the cutset, which results in an empty string.
strings.trim("str", "str") // ""
Example 2
In 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.
strings.trim("str", "") = "str"
Example 3
In the following example, the function yields an empty string because the input string is already empty and there are no characters to remove.
strings.trim("", "str") = ""
Example 4
In the following example, the function yields str because the trim function removes the following:
- trailing whitespace in "a aastraa aa "
- the characters specified in the cutset (space, a)
strings.trim("a aastraa aa ", " a") = "str"
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."],[[["\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\""]]