title: Getting full sentences from index of word
body: <p>I am trying to find a more elegant way than the below code to get a list of sentences based on the index of one of the containing words. So for example if I give it a list of words, such as user names, it finds the index of all of those words (this is done already and is the GetWordsMatches method) and then, using the index of that word, I want to grab the whole sentence.</p>
  
  <p>I have two problems, one, I can't figure out how to look before the word to the previous period, just the end one, two, I cant figure out how to stop it from crashing if the last word match does not have a period before the end of the file.</p>
  
  <pre><code>public static List&lt;string&gt; GetSentencesFromWords(List&lt;string&gt; Words, string FileContents)
      {
          List&lt;string&gt; returnList = new List&lt;string&gt;();
          MatchCollection mColl = GetWordsMatches(Words,FileContents);
          foreach (Match ma in mColl)
          {
              int tmpInd = ma.Index;
              int endInd = FileContents.IndexOf(".", tmpInd);
              string tmp = FileContents.Substring(tmpInd,endInd);
              returnList.Add(tmp);
          }
          return returnList;
      }
  </code></pre>
  
  <p>Is there a more elegant way to do this?</p>