-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program (6).cs
80 lines (75 loc) · 2.7 KB
/
Program (6).cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace Homework7
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, string> PhoneBook = new Dictionary<string, string>();
string path = @"C:\Users\V\Desktop\SoftServe\phonebook.txt";
string pathWrite = @"C:\Users\V\Desktop\SoftServe\phones.txt";
string pathWrite2 = @"C:\Users\V\Desktop\SoftServe\New.txt";
try
{
FileInfo f = new FileInfo(pathWrite);
if (!f.Exists) { f.Create(); }
using (StreamReader myStreamReader = new StreamReader(path, System.Text.Encoding.Default))
{
string[] myFile = new string[9];
string name, number;
for (int i = 0; i < 9; i++)
{
myFile[i] = myStreamReader.ReadLine();
number = myFile[i].Substring(0, 11);
name = myFile[i].Substring(12);
PhoneBook.Add(number, name);
}
}
using (StreamWriter myStreamWriter = new StreamWriter(pathWrite, true, System.Text.Encoding.Default))
{
foreach (var item in PhoneBook.Keys)
{
myStreamWriter.WriteLine(pathWrite);
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Write("Enter person name:");
string personName = Console.ReadLine();
foreach (var el in PhoneBook)
{
if (el.Value.ToLower().Contains(personName.ToLower()))
{
Console.WriteLine($"Person {personName} has number {el.Key}");
}
}
try
{
using (StreamWriter myStreamWriter2 = new StreamWriter(pathWrite2, false, System.Text.Encoding.Default))
{
foreach (var item in PhoneBook.Keys)
{
if (!item.StartsWith("+3"))
{
myStreamWriter2.WriteLine("+3" + item);
}
else
{
myStreamWriter2.WriteLine(item);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}