컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
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이 아닌 하위 문자열을 사용합니다. 하위 문자열은 2개 이상의 문자로 구성되어 있으며 2회 이상 발생합니다.
strings.count_substrings("fooABAbarABAbazABA", "AB") = 3
예시 7
이 예에서는 null이 아닌 문자열과 null이 아닌 하위 문자열을 사용합니다. 하위 문자열은 2개 이상의 문자로 구성되어 있으며 2회 이상 발생합니다. 중복되는 하위 문자열 발생의 제한사항을 강조합니다.
strings.count_substrings("ABABABA", "ABA") = 2
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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"]]