Given a particular String and a particular word that appears in that String, how can I calculate the number of words that preceded that word?
For instance, given the sentence "I live in a red house on the farm" and the word "red", how can I determine how many words came before the word? I'd like to create a function that takes the original String and the target word as parameters and prints a statement like:
There are 4 words before the word "red"