-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5.cs
More file actions
38 lines (32 loc) · 1.05 KB
/
task5.cs
File metadata and controls
38 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.IO;
namespace task5 {
class Program {
static void view(string text, string word) {
char[] sepparators = { '\n', '.', '!', '?', ';' };
string[] lines = text.Split(sepparators);
for (int i = 0; i < lines.Length; i++) {
if (lines[i].Contains(word)) {
Console.WriteLine(lines[i]);
}
}
}
static void Main(string[] args) {
string text;
string word;
string filepath;
Console.Write("File path: ");
filepath = Console.ReadLine();
Console.Write("Search word: ");
word = Console.ReadLine();
if (File.Exists(filepath)) {
text = File.ReadAllText(filepath);
Console.WriteLine("Result");
view(text, word);
} else {
Console.WriteLine("File not found.");
}
Console.ReadKey();
}
}
}