svetlozar_kirkov

Extract sentences with keyword (Exercise)

Oct 10th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleTests
  5. {
  6.     class ConsoleTests
  7.     {
  8.         static void Main()
  9.         {
  10.             string input = Console.ReadLine();
  11.             string wordSearched = Console.ReadLine();
  12.             Extract(input, wordSearched);
  13.  
  14.         }
  15.  
  16.         public static void Extract(string str, string keyword)
  17.         {
  18.             string[] arr = str.Split('.');
  19.             string answer = string.Empty;
  20.  
  21.             foreach(string sentence in arr)
  22.             {
  23.                 string[] words = sentence.Split(new char[] { ' ', ',' });
  24.                 if(words.Contains(keyword,StringComparer.CurrentCultureIgnoreCase))
  25.                 {
  26.                     Console.WriteLine(sentence.Trim()+'.');
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment