To illustrate further, let's say we want to count the number of times the word
"business" from the following definition of "Business Intelligence":
"Business Intelligence, or simply BI, is a process of gathering, storing,
processing, analyzing and disseminating decision-making information to business
leaders to help them make better business decision."
The first step in the user-defined function is to replace the search string from
the second string. So replacing the string "business" from the previous
text will give use the following result:
" Intelligence, or simply BI, is a process of gathering, storing,
processing, analyzing and disseminating decision-making information to
leaders to help them make better decision."
The next step is subtracting the length of the resulting text after the replace
from the length of the original text. The original text has a length of
204 while the resulting text has a length of 180, giving us a difference of 24.
The last step determines the number of times the search string occurred in the
other string. This is accomplished by dividing the difference between the
length original text and length of the resulting text, which is 24, by the
length of the string being searched for, which is 8, giving the result of 3,
the number of times the word "business" occurred in the long text above.