Advertisement
stanevplamen

02.8.08.SentenceExtract

Jun 13th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class SentenceExtract
  5. {
  6.     static void SubstringCounter(string text, string target)
  7.     {
  8.         //string[] sentsArray = text.Split('.', '?', '!');
  9.         string[] splitters = new string[] { ". ", ".\t", "." + Environment.NewLine }; //
  10.         string[] sentsArray = text.Split(splitters, StringSplitOptions.None); // the other option
  11.         foreach (var sentence in sentsArray)
  12.         {
  13.             string[] wordsArray = sentence.Split(',', '-', ' ');
  14.             bool sign = false;
  15.             foreach (var word in wordsArray)
  16.             {
  17.                 if (word == target)
  18.                 {
  19.                     sign = true;
  20.                     continue;
  21.                 }
  22.             }
  23.             if (sign == true)
  24.             {
  25.                 Console.WriteLine(sentence);
  26.             }
  27.         }
  28.     }
  29.  
  30.     static void Main()
  31.     {
  32.         string someText = "We are living in an 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.";
  33.         string target = "in";
  34.         SubstringCounter(someText, target);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement