-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKod26_StringSplitTrim.cs
More file actions
34 lines (28 loc) · 1.04 KB
/
Kod26_StringSplitTrim.cs
File metadata and controls
34 lines (28 loc) · 1.04 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
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;
/*Задача 26:Split + Join + Replace
Введи строку (например: "hello world! test")
Убери все лишние пробелы, замени "!" на "?" и выведи слова через запятую.
Ожидаемый вывод: hello, world?, test*/
class Program
{
static void Main()
{
Console.Write("Введите строку: ");
string input = Console.ReadLine()?.Trim() ?? "";
if (string.IsNullOrWhiteSpace(input))
{
Console.WriteLine("Ничего не введено");
return;
}
string withQ = input.Replace("!", "?");
string[] words = withQ.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string result = string.Join(", ", words);
Console.WriteLine(result);
}
}