-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringsOAiP.cs
66 lines (52 loc) · 2.24 KB
/
StringsOAiP.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
namespace StringsOAiP;
public class StringsOAiP
{
// Поля для задания 1
private static string? _line;
private static readonly string _workForCheck = "интересно";
private static readonly string _wordToReplace = "Программирование";
private static readonly string _targetWordReplace = "Разработка";
// Поля для задания 2
private static string? _userName;
private static uint _userAge;
public static void Main(string[] args)
{
// Задание 1
Exercise1();
// Задание 2
Exercise2();
}
private static void Exercise1()
{
// Задание 1.1
string _line = "Программирование на С# - это интересно!";
// Задание 1.2
Console.WriteLine($"Длина строки \"{_line}\" равна {_line.Length}.\n");
// Задание 1.3
_line.ToCharArray();
for (var i = _line.Length - 1; i >= 0; i--)
Console.Write(_line[i]);
// Задание 1.4
if (_line.Contains(_workForCheck))
Console.WriteLine($"\n\nСлово \"{_workForCheck}\" есть в \"{_line}\".");
else
Console.WriteLine($"\n\nСлова \"{_workForCheck}\" нет в \"{_line}\".");
// Задание 1.5
string resultLine = _line.Replace(_wordToReplace, _targetWordReplace);
Console.WriteLine($"\nОбновлённая строка: {resultLine}\n\n");
}
private static void Exercise2()
{
// Задание 2.1
Console.WriteLine($"Введите ваше имя: ");
_userName = Console.ReadLine();
Console.WriteLine($"Введите ваш возраст: ");
_userAge = Convert.ToUInt32(Console.ReadLine());
// Задание 2.2
string userInfo = string.Format("\nСТРОКА С ФОРМАТОМ\nПривет, {0}! Тебе {1} лет.", _userName, _userAge);
Console.WriteLine(userInfo);
// Задание 2.3
userInfo = $"СТРОКА С ИНТЕРПОЛЯЦИЕЙ:\nПривет, {_userName}! Тебе {_userAge} лет.";
Console.WriteLine(userInfo);
}
}