containsCount

containsCount, function

def pure containsCount(haystack: text, needle: text): number

Returns the number of non-overlapping occurrences of the needle within the haystack.

Example

haystack = "Hello World!"
show summary "" a1c2 with
  containsCount(haystack, "l") as "Contains 'l'?"         // '3'
  containsCount(haystack, "World") as "Contains 'World'?" // '1'

Errors

Needle is an empty string.

The needle cannot be an empty text value.

Remarks

This function is case-sensitive.

Recipes and best practices

This function should not be used to get the number of fields in a text containing separators. You should use the fieldCount function to do that instead.

See also

User Contributed Notes
0 notes + add a note