使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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"
如未另行说明,那么本页面中的内容已根据知识共享署名 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。"],[[["\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\""]]