Skip to main content


Returns the number of instances of a substring in a string.




string The string to search for instances of substring. An expression that resolves to a string.
substring A substring to match against string. An expression that resolves to a string.


The COUNT function returns the number of times a specified substring appears in string.

String matching is case-sensitive. Numbers are converted to canonical form, with leading and trailing zeroes and plus signs removed. Numeric strings are not converted to canonical form.

If string is an empty string ("") COUNT returns a count of 0. If substring is an empty string, COUNT returns a count equal to the number of characters in string.


The following example uses the COUNT function to return the number of appearance of a substring in a string:

PRINT COUNT("InterSystems","s");  ! Returns 2
PRINT COUNT("InterSystems","S");  ! Returns 1
PRINT COUNT("InterSystems","te"); ! Returns 2
PRINT COUNT(+0099.900,0);         ! Returns 0
PRINT COUNT("0099.900",0);        ! Returns 4
PRINT COUNT("InterSystems","");   ! Returns 12

The following example shows that overlapping substrings are only counted once:

PRINT COUNT("AAAAA","AA");        ! Returns 2

See Also

FeedbackOpens in a new tab