Description

Counts the number of occurrences of a substring in a string, returning 1 if the there are no occurrences of the substring in the string. (Introduced in OpenInsight 4.1.2.)

Syntax

instances = DCount (source_string, search_string)

Parameters

The DCount function has the following parameters.

ParameterDescription
source_stringIdentifies the string to search for in search_string. Can be a literal string, expression, constant, or variable.
search_stringIdentifies the string to search for in source_string. search_string may be a literal string, expression, constant, or variable.

If search_string does not appear in source_string, or if search_string is null, a 0 (zero) will be returned.

The Count() and DCount() functions are usually used to determine the size of a dynamic array. They actually have more general purpose use, because the search string can be any string used as a delimiter, even multiple character strings.

Note: To count the number of values in a dynamic array, you need to account for the possibility that the array has one value, with no delimiter. The count() function in this case will return 0 because there is no delimiter in the string. To return the correct answer (1), you need to add the boolean expression ( var # ), which returns 1 if the variable contains a value but 0 if it is null. See the example below.

Note: If you use dcount() to count the number of values in a dynamic array, you do not need to add the boolean expression because dcount() returns the proper result (1) if the array has one value with no delimiter.

See Also

Count()

Example

* count the number of items in an @fm-delimited list
 
declare function dcount
cnt = dcount(List, @fm)
  • No labels

1 Comment

  1. In OpenInsight 9, if source_string is unassigned, it will get assigned an empty string and not raise an error. In OpenInsight 10, this will product a VNAV error within the DCount function.