vbams-accessms-access-2010

How do I count the number of times a string appears within another string in VBA?


How do I count the number of times one string appears within another in Access VBA? For example, how would I count how many times "the" occurs in "The quick brown fox jumps over the lazy dog."?


Solution

  • As you are ok with substrings/case sensitivity

    matches = (len(lookin) - len(replace$(lookin, find, ""))) / len(find)