Grep без регулярных выражений - C#
Формулировка задачи:
пытаюсь написать аналог grep из Linux, имеется вот такой код:
но при компиляции, когда я ввожу фильтр(слово, которое содержится в тексте), мне выдается полностью текст на экран, а не те строки, которые содержат слово из filter, что делать?
static void Main(string[] args)
{
string text = File.ReadAllText("test.txt");
Console.WriteLine(text);
Console.WriteLine("Задайте фильтр");
string filter = Console.ReadLine();
foreach(var line in text){
if (text.Contains(filter))
{
Console.Write("{0} ", line);
}
}
Console.WriteLine("Press Enter");
Console.ReadLine();
}
сам текст вот такой:
Me: Hi!
John: Hello Daniel!
Me: So, uh... what's up?
John: Nothing much.
Me: Well, in my case, I ate loads of pastizzi yesterday, and I feel I might explode.
John: Great, you might take down the Luqa monument in doing so.
Me: Thanks, I'm flattered by your concern.
John: What are pastizzi anyway?
Me: The Maltese fast food. Very good, very unhealthy.
Решение задачи: «Grep без регулярных выражений»
textual
Листинг программы
File.ReadAllText