One approach could be to use IndexOf.

1. Find the word 'find' and save the index as indexFind.

2. Find the word 'all', starting from indexFind and save this index as indexAll.

3. Check if you can find the word 'them' between the two indices.

4. If not, repeat from step 2 using indexAll as the start position.

5. Finally, copy the sub-string between indexFind and indexAll.

Note: You also need to check that, for example, the sequence does not contain duplicates like 'find them

**find them all**'. In this case I presume you want only the last part of the string.

If you need a more generic solution, you can adapt the solution something like this:

1. Find the first word from set T in set S and save the index as indexFirst.

2. Find the last word from set T in set S, starting from indexFirst and save this index as indexLast.

3. Loop through set T and check if the words appear in sequence and only once (no duplicates).

4. If not, do another search round.

I hope this helps you further with your school work.

It is not a ready solution, just a pointer for the way forward.

http://www.codeproject.com/Questions/1002542/Find-the-shortest-continuous-subsequence-of-words?arn=0