Description
The count
function returns the number of occurrences of the substring needle
within the string haystack
.
Syntax
count(haystack, needle)
Arguments
Argument | Description |
---|---|
haystack |
The string in which the occurrences are to be counted. |
needle |
The substring whose occurrences within haystack are to be counted. |
Return Types
The function returns the number of occurrences of needle
in haystack
as an integer.
Examples
Description | Formula | Result |
---|---|---|
Simple word count |
count("Banana Banana Apple", "Banana") |
2 |
Counting a character |
count("abcabcabc", "a") |
3 |
Substring in a sentence |
count("This is a Test. Test Test!", "Test") |
3 |
Notes
- Case sensitivity: The search is case-sensitive. Uppercase and lowercase letters must match.
- Substring not found: If
needle
is not found inhaystack
, the function returns 0.
Comments
0 comments
Please sign in to leave a comment.