How to count occurences of specific word in long string ..?
Printable View
How to count occurences of specific word in long string ..?
if you split the string, the ubound of the array should be the number of occurences
pete
Yeah! I was trying to code a function that uses a look and instr..
You just need to split the string with the word you want to count, and the num of occurences is the ubound + 1, since Arrays start at 0. :)
Hmm...for some reason, its not Ubound + 1...
-Sir Loin
You could loop through the string using Mid$ and Instr to move word by word counting the matches of your specific word.
Or you could do like suggested with the splitting of the text into an array, but loop through the array testing for matches of your word. ;)
if need be it may be better to split with a space before and after the word, in case that word can be part of a longer word
pete
Oh ya, if its multiple words or a phrase then the Mid and Instr functions are better. ;)