CountOccurrences

The FireflyAIO Lua API provides a CountOccurrences function to count how many times a specific substring appears within a given text.

Counting Substring Occurrences

To count the occurrences of a substring in a text, use the CountOccurrences function by providing the main text and the substring you want to count as arguments.

Here is an example:

-- Count the occurrences of "Hello" in the text
local count = CountOccurrences("Hello Hello Hello World!", "Hello")

In this example, the function call CountOccurrences("Hello Hello Hello World!", "Hello") will return 3, as the substring "Hello" appears three times in the text "Hello Hello Hello World!".

Using the CountOccurrences function helps in scenarios where you need to analyze the frequency of specific words or phrases within a text, aiding in tasks such as data analysis, text processing, or pattern recognition.

Last updated