Advertisement
Krissy

Extract sentences

Jan 27th, 2013
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7.  
  8. class ExtractSentences
  9. {
  10.     static void Main()
  11.     {
  12.         string text="We are living in a yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.";
  13.         string word = "in";
  14.         string[] sentences=text.Split('.');
  15.  
  16.         for (int i = 0; i < sentences.Length; i++)
  17.         {
  18.             if (Regex.Matches(sentences[i],@"\b"+word+@"\b").Count>0)
  19.             {
  20.                 Console.WriteLine((sentences[i] + ".").Trim());
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement