title: LINQ split string into sentences dependently to quotes
body: <p>How to split text into sentences in a text; with dots, question marks, exclamation marks etc. I'm trying to get every sentence one by one except inside of quotes. </p>
  
  <p>For example split this: </p>
  
  <pre><code>Walked. Turned back. But why? And said "Hello world. Damn this string splitting things!" without a shame.
  </code></pre>
  
  <p>Like this:</p>
  
  <pre><code>Walked. 
  Turned back. 
  But why? 
  And said "Hello world. Damn this string splitting things!" without a shame.
  </code></pre>
  
  <p>I'm using this code:</p>
  
  <pre><code> private List&lt;String&gt; FindSentencesWhichContainsWord(string text, string word)
          {
              string[] sentences = text.Split(new char[] { '.', '?', '!' }, StringSplitOptions.RemoveEmptyEntries);
  
              // Define the search terms. This list could also be dynamically populated at runtime.
              string[] wordsToMatch = { word };
  
              // Find sentences that contain all the terms in the wordsToMatch array.
              // Note that the number of terms to match is not specified at compile time.
              var sentenceQuery = from sentence in sentences
                                  let w = sentence.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' },
                                                          StringSplitOptions.RemoveEmptyEntries)
                                  where w.Distinct().Intersect(wordsToMatch).Count() == wordsToMatch.Count()
                                  select sentence;
  
              // Execute the query. Note that you can explicitly type
              // the iteration variable here even though sentenceQuery
              // was implicitly typed. 
  
              List&lt;String&gt; rtn = new List&lt;string&gt;();
              foreach (string str in sentenceQuery)
              {
                  rtn.Add(str);
              }
              return rtn;
          }
  </code></pre>
  
  <p>But it's giving the result below which is not I wish.</p>
  
  <pre><code>Walked. 
  Turned back. 
  But why? 
  And said "Hello world.
  Damn this string splitting things!
  " without a shame.
  </code></pre>