fork(1) download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6.  
  7. public static string Extract(string str, string keyword)
  8. {
  9.  
  10. string[] arr = str.Split('.');
  11. string answer = string.Empty;
  12.  
  13. foreach(string sentence in arr)
  14. {
  15. if(sentence.Split(' ').Any(w => w == keyword))
  16. answer += sentence+". ";
  17. }
  18.  
  19. return answer;
  20. }
  21.  
  22. public static void Main()
  23. {
  24. string example = "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.";
  25.  
  26. string keyword = "in";
  27. string answer = Extract(example, keyword);
  28. Console.WriteLine(answer);
  29. }
  30. }
Success #stdin #stdout 0.03s 33888KB
stdin
Standard input is empty
stdout
We are living in a yellow submarine.  We will move out of it in 5 days.