Advertisement
Guest User

Untitled

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