Extracting phrases from a string
===

I have a text file that I need to search and then print to screen certain phrases from it.

I can bring the text file into a string and find the index of thefirst part of the phrase like so;

    int first = source.IndexOf(start-keyword);

Where source is the text file string and start-of-phrase is the first keyword I'm looking for.

However when I try to get the index of the end keyword I get stuck as sometimes the end keyword comes before the first keyword.

So I added the following bit to my code so it looks like:

    int first = source.IndexOf(start-keyword);
    string source2 = source.Substring(first, source.Length - first);
    int last = source2.IndexOf(end-keyword) + end-keyword.Length;
    phrases.Add(source.Substring(first, last));

Then the last line adds it to a list called phrases.

However I can't seem to find a satisfactory way to loop this as I start getting errors such as Out of range or not extracting the full phrase?

Thanks
