COUNT Function

The COUNT function determines how many times a character or string of characters occur within a specified string.

Format

COUNT(string,chars)

Parameter(s)

string

An expression evaluating to the string to be searched.

chars

An expression evaluating to the substring to be searched for and counted.

Description

The COUNT function returns the number of times a substring is repeated within a string. The COUNT function returns zero if the substring is not found. If the substring is the null string, the function returns the number of characters in the string minus one.

The COUNT function actually counts the number of starting points for the specified substring within the string. That is, for each character in the string, it determines whether an occurrence of the specified substring begins at that character. If it does, its return value is incremented by one. This means that if there are overlapping occurrences of the substring within the string, COUNT returns as many occurrences as it can find, regardless of whether the starting character is a part of a previous occurrence.

The DCOUNT function returns the number of fields separated by a given 1-character delimiter. See DCOUNT Function for more information.

Example

To assign the variable NUMS to the number of times the substring "ANA" occurs in the string "BANANA", type:

NUMS = COUNT("BANANA","ANA")

Note that the two occurrences of "ANA" overlap.

See Also

Statement and Function Reference