You could spend a whole lot of time and money on this. For example, what is a word? As well as the normal "separated by spaces" requirement, what if there is a double space somewhere? Will hyphens, carriage returns, parenthesis, brackets, braces, and other special characters be treated as spaces?
My recommendation is to NOT redevelop the proverbial wheel. See the following product, please. And, no, I don't work for them. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.