using System; using System.Linq; public class Test { public static string Extract(string str, string keyword) { string[] arr = str.Split('.'); string answer = string.Empty; foreach(string sentence in arr) { if(sentence.Split(' ').Any(w => w == keyword)) answer += sentence+". "; } return answer; } public static void Main() { 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."; string keyword = "in"; string answer = Extract(example, keyword); Console.WriteLine(answer); } }