コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
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 以外の文字列と、複数文字の 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-02-24 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-02-24 UTC。"],[[["The `strings.count_substrings` function calculates the number of non-overlapping instances a specified substring appears within a given string."],["It takes two string inputs: the string to search within and the substring to count, and then returns an integer representing the count."],["An empty substring or an empty string input, in any combination, will result in a returned count of 0."],["Overlapping occurrences of the substring are not counted; only distinct, non-overlapping instances are included in the count."],["This function is supported within both Rules and Search."]]],[]]