Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace FileDetails
  9. {
  10.     class FileDetails
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             try
  15.             {
  16.                 Console.OutputEncoding = Encoding.UTF8;
  17.                 //args = new string[] { "text.txt" };
  18.                 Console.WriteLine(args.Length);
  19.                 foreach (var arg in args)
  20.                 {
  21.                     Console.WriteLine(arg);
  22.                 }
  23.                 var filename = args[0];
  24.  
  25.                 FileStream stream = new FileStream(filename, FileMode.Open);
  26.                 StreamReader reader = new StreamReader(stream);
  27.                 var streamLength = stream.Length;
  28.                 var contents = new char[streamLength];
  29.  
  30.                 for (int i = 0; i < streamLength; i++)
  31.                 {
  32.                     contents[i] = (char)reader.Read();
  33.                 }
  34.                 Summarize(contents, out int vowelCount);
  35.                 Console.WriteLine(contents);
  36.                 Console.WriteLine($"Всего букв - {streamLength}\n" +
  37.                     $"Глассные - {vowelCount}\n" +
  38.                     $"Согласные - {streamLength - vowelCount}");
  39.                 reader.Close();
  40.                 stream.Close();
  41.             }catch(Exception ex)
  42.             {
  43.                 Console.WriteLine(ex);
  44.             }
  45.             Console.ReadKey();
  46.         }
  47.  
  48.         static public void Summarize(char[] contents, out int vowelCount)
  49.         {
  50.             vowelCount = 0;
  51.             foreach (var ch in contents)
  52.             {
  53.                 if("AEIOUaeiou".IndexOf(ch) != -1)
  54.                 {
  55.                     vowelCount++;
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement