4DM3M

19

Jan 3rd, 2022
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Drafty
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string filename;
  11.  
  12.             Console.Write("Введите имя текстового документа на диске D: ");
  13.             filename = Console.ReadLine();
  14.  
  15.             string path = @$"D:\{filename}.txt";
  16.  
  17.             if (!File.Exists(path))
  18.             {
  19.                 Console.WriteLine("Файл не найден");
  20.                 return;
  21.             }
  22.  
  23.             string content = File.ReadAllText(path);
  24.             string[] elements = content.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  25.  
  26.             Console.WriteLine($"В файле {elements.Length} чисел");
  27.             for (int i=0; i<elements.Length; i++)
  28.             {
  29.                 Console.Write(elements[i] + " ");
  30.             }
  31.  
  32.             Console.WriteLine();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment