This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
123 lines (99 loc) · 4.74 KB
/
Program.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.IO;
using System.Linq;
using System.Text;
namespace lab_02
{
public class Program
{
public static void Main(string[] args)
{
var output = "";
var filePath = GetLongTextPath();
PrintLongFileContents(filePath);
var comment = ReadComment();
Console.Clear();
Console.WriteLine(output += "\n" + new string('-', 33));
var everyWordCapitalized = TextTransform.ToTitleCase(comment);
output += "\n" + "а. Кожне слово починається з великої літери " + everyWordCapitalized;
PrintLastLine(output);
var vowelsToRandomInts = TextTransform.ReplaceVowels(comment);
output += "\n" + "b. Кожна голосна літера замінена рандомним числом від 0 до 9 " + vowelsToRandomInts;
PrintLastLine(output);
var doubledUpperCaseLetters = TextTransform.DoubleUpperCaseLetters(comment);
output += "\n" + "с. Літери, які були введені користувачем в UpperCase здубльовані " +
doubledUpperCaseLetters;
PrintLastLine(output);
var withoutThirdWord = TextTransform.RemoveThirdWord(comment);
output += "\n" + "d Третє слово видалене " + withoutThirdWord;
PrintLastLine(output);
var withMiracle = TextTransform.InsertMiracle(comment);
output += "\n" + "e Між п`ятим і шостим словом вставлене слово - miracle " + withMiracle;
PrintLastLine(output);
var joined78 = TextTransform.Join78(comment);
output += "\n" + "f 7 i 8 слово об'єднанні разом " + joined78;
PrintLastLine(output);
output += "\n" + new string('*', 5);
PrintLastLine(output);
output += "\n" + new string('=', 10) + "Статистика" + new string('=', 10);
PrintLastLine(output);
var statistics = BuildCommentStatistic(comment);
output += "\n" + statistics;
PrintLastLine(output);
File.WriteAllText(filePath, output);
}
private static void PrintLastLine(string text)
{
Console.WriteLine(text.Split('\n').Last());
}
private static string BuildCommentStatistic(string comment)
{
var statsBuilder = new StringBuilder();
statsBuilder.AppendLine($"{comment.Count(char.IsDigit)} - цифр");
statsBuilder.AppendLine($"{comment.Count(char.IsLetter)} - букв");
statsBuilder.AppendLine($"{comment.Count(char.IsLetterOrDigit)} - букв і цифр");
statsBuilder.AppendLine($"{comment.Count(char.IsLower)} - символів в LowerCase");
statsBuilder.AppendLine($"{comment.Count(char.IsUpper)} - символів в UpperCase");
statsBuilder.AppendLine($"{comment.Count(char.IsPunctuation)} - розділових знаків");
statsBuilder.AppendLine($"{comment.Count(char.IsSeparator)} - знаків розділювачів");
statsBuilder.AppendLine($"{Math.Min(comment.IndexOf('a'), comment.IndexOf('A'))} - index of A|a");
statsBuilder.AppendLine($"Vote index - {comment.LastIndexOfAny(new[] {'a', 'e', 'i', 'o', 'u'})} - "
+ "порядковий номер голосної з кінця оригінального тексту");
return statsBuilder.ToString();
}
private static void PrintLongFileContents(string filePath)
{
var fileContent = File.ReadLines(filePath);
Console.WriteLine("File content: ");
foreach (var line in fileContent)
{
Console.WriteLine(line);
}
}
private static string GetLongTextPath()
{
Console.WriteLine("Please enter path to LongText.txt");
return Path.Combine(Console.ReadLine(), "LongText.txt");
}
private static string ReadComment()
{
var comment = "";
Console.WriteLine("Please enter your comment");
while (true)
{
var line = Console.ReadLine();
if (line != null && line.Length == 0)
{
continue;
}
var pressedCtrlE = line != null && line.ToCharArray()[0] == 5;
if (pressedCtrlE)
{
break;
}
comment += line + '\n';
}
return comment;
}
}
}