-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKod28_IndexOfSubstring.cs
More file actions
47 lines (41 loc) · 1.28 KB
/
Kod28_IndexOfSubstring.cs
File metadata and controls
47 lines (41 loc) · 1.28 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
39
40
41
42
43
44
45
46
using System.Diagnostics;
using System.Reflection.Metadata.Ecma335;
using System.Reflection.PortableExecutable;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Collections;
using System.Text;
/*Задача 28:IndexOf + Substring
Дан email (ввод с клавиатуры).
Вырежи и выведи только домен (всё после @).*/
class Program
{
static void Main()
{
Console.Write("Введите email: ");
string email = Console.ReadLine()?.Trim() ?? string.Empty;
if (string.IsNullOrWhiteSpace(email))
{
Console.WriteLine("Email не введён");
return;
}
if (email.Contains('@'))
{
int atIndex = email.IndexOf('@');
string domain = email.Substring(atIndex + 1);
if (string.IsNullOrEmpty(domain))
{
Console.WriteLine("Некорректный email: после @ ничего нет");
}
else
{
Console.WriteLine($"Домен: {domain}");
}
}
else
{
Console.WriteLine("Некорректный email: отсутствует символ '@'");
}
}
}