コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
strings.count_substrings
strings.count_substrings(string_to_search_in, substring_to_count)
説明
文字列と部分文字列を指定すると、文字列内で重複しない部分文字列の出現回数の int64 を返します。
パラメータのデータ型
STRING
、STRING
戻り値の型
INT
コードサンプル
このセクションでは、特定の文字列に部分文字列が出現する回数を計算する例を示します。
例 1
この例では、null 以外の文字列と、null 以外の単一の部分文字列文字を使用しています。
strings.count_substrings("this`string`has`four`backticks", "`") = 4
例 2
この例では、null 以外の文字列と、1 文字以上の null 以外の部分文字列を使用しています。
strings.count_substrings("str", "str") = 1
例 3
この例では、null 以外の文字列と空の部分文字列を使用しています。
strings.count_substrings("str", "") = 0
例 4
この例では、空の文字列と、1 文字以上の null 以外の部分文字列を使用しています。
strings.count_substrings("", "str") = 0
例 5
この例では、空の文字列と空の部分文字列を使用しています。
strings.count_substrings("", "") = 0
例 6
この例では、null 以外の文字列と、複数文字で複数回出現する null 以外の部分文字列を使用しています。
strings.count_substrings("fooABAbarABAbazABA", "AB") = 3
例 7
この例では、null 以外の文字列と、複数文字で複数回出現する null 以外の部分文字列を使用しています。重複する部分文字列の出現に関する制限がハイライト表示されます。
strings.count_substrings("ABABABA", "ABA") = 2
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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\u003eThe \u003ccode\u003estrings.count_substrings\u003c/code\u003e function calculates the number of non-overlapping instances a specified substring appears within a given string.\u003c/p\u003e\n"],["\u003cp\u003eIt takes two string inputs: the string to search within and the substring to count, and then returns an integer representing the count.\u003c/p\u003e\n"],["\u003cp\u003eAn empty substring or an empty string input, in any combination, will result in a returned count of 0.\u003c/p\u003e\n"],["\u003cp\u003eOverlapping occurrences of the substring are not counted; only distinct, non-overlapping instances are included in the count.\u003c/p\u003e\n"],["\u003cp\u003eThis function is supported within both Rules and Search.\u003c/p\u003e\n"]]],[],null,["### strings.count_substrings\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n strings.count_substrings(string_to_search_in, substring_to_count)\n\n#### Description\n\nWhen given a string and a substring, returns an int64 of the count of non-overlapping occurrences of the substring within the string.\n\n#### Param data types\n\n`STRING`, `STRING`\n\n#### Return type\n\n`INT`\n\n#### Code samples\n\nThis section contains examples that calculate the number of times a substring appears in a given string.\n\n##### Example 1\n\nThis example uses a non-null string and a non-null single substring character. \n\n strings.count_substrings(\"this`string`has`four`backticks\", \"`\") = 4\n\n##### Example 2\n\nThis example uses a non-null string and a non-null substring greater than one character. \n\n strings.count_substrings(\"str\", \"str\") = 1\n\n##### Example 3\n\nThis example uses a non-null string and an empty substring. \n\n strings.count_substrings(\"str\", \"\") = 0\n\n##### Example 4\n\nThis example uses an empty string and a non-null substring greater than one character. \n\n strings.count_substrings(\"\", \"str\") = 0\n\n##### Example 5\n\nThis example uses an empty string and an empty substring. \n\n strings.count_substrings(\"\", \"\") = 0\n\n##### Example 6\n\nThis example uses a non-null string and a non-null substring that is greater than one character and greater than one occurrence. \n\n strings.count_substrings(\"fooABAbarABAbazABA\", \"AB\") = 3\n\n##### Example 7\n\nThis example uses a non-null string and a non-null substring that is greater than one character and greater than one occurrence. It highlights the limitation with overlapping substring occurrences \n\n strings.count_substrings(\"ABABABA\", \"ABA\") = 2"]]