Advertisement
inf3qt0r

ExtractSentences

Jan 29th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. namespace ExtractSentences
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.  
  6.     public class ExtractSentences
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             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.";
  11.             string key = "in";
  12.  
  13.             for (int i = 0; i < text.Length; i++)
  14.             {
  15.                 int currentDotIndex = text.IndexOf(".", i);
  16.                 string currentStr = text.Substring(i, currentDotIndex - i + 1);
  17.                 if (Regex.IsMatch(currentStr, @"\b" + key + @"\b."))
  18.                 {
  19.                     Console.WriteLine(currentStr);
  20.                 }
  21.  
  22.                 i = currentDotIndex + 1;
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement