Advertisement
Guest User

Untitled

a guest
May 4th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System; // Console
  2. using System.IO; // FileStream, FileReader
  3.  
  4. class FileDetails
  5. {
  6. // Подсчет гласных, согласных и строк
  7. public static void Summarize(char[] contents)
  8. {
  9. int vowel = 0, notvowel = 0, count = 1;
  10. foreach (char symbol in contents)
  11. {
  12. if ("AEIOUaeiou".IndexOf(symbol) != -1)
  13. vowel++;
  14. else
  15. notvowel++;
  16. if (symbol == '\r')
  17. count++;
  18. }
  19. Console.WriteLine("Vowels:{0}\nNon-vowels: {1}\nStrings: {2} \nOverall count: {3}", vowel, notvowel, count, vowel + notvowel);
  20. }
  21.  
  22. static void Main(string[] args)
  23. {
  24. // Имя файла
  25. string filename;
  26. Console.WriteLine("Arguments count: {0}", args.Length);
  27. //foreach (string arg in args)
  28. // Console.ReadLine(arg);
  29. try
  30. {
  31. if (args.Length == 1) // Если есть аргумент
  32. {
  33. // Передаем аргумент в имя файла и открываем поток
  34. filename = args[0];
  35. FileStream stream = new FileStream(filename, FileMode.Open);
  36. StreamReader reader = new StreamReader(stream);
  37.  
  38. // Вычисляем длину файла
  39. int length = Convert.ToInt32(stream.Length);
  40.  
  41. // Создаем массив для текста и копируем текст из файла
  42. char[] contents = new char[length];
  43. for (int i = 0; i < length; i++)
  44. contents[i] = Convert.ToChar(reader.Read());
  45. reader.Close(); // Закрываем поток
  46.  
  47. // Вывод результата
  48. Console.WriteLine(contents);
  49. Summarize(contents);
  50. Console.WriteLine("Complete.");
  51. };
  52. }
  53. // Обработка исключения (если файл с таким именем не найден)
  54. catch (FileNotFoundException)
  55. {
  56. Console.WriteLine("File not found.");
  57. }
  58. Console.ReadKey();
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement