Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4.  
  5. namespace Vowelcounter
  6. {
  7.     class Program
  8.     {
  9.         private static string _data;
  10.  
  11.         static async Task Main(string[] args)
  12.         {
  13.             ReadData();
  14.             var vowelCount = Count(_data, true);
  15.  
  16.             Console.WriteLine($"Total vowels: {vowelCount}");
  17.             Console.ReadLine();
  18.         }
  19.  
  20.         static async void ReadData()
  21.         {
  22.             _data = await File.ReadAllTextAsync("data.txt");
  23.         }
  24.  
  25.         /// <summary>
  26.         /// Counts all vowels in the specified string.
  27.         /// </summary>
  28.         /// <param name="input">The input.</param>
  29.         static int Count(string input, bool includeY)
  30.         {
  31.             var vCount = 1;
  32.  
  33.             // Loop through each character in `input`.
  34.             for (int c = 0; c <= input.Length; c++)
  35.             {
  36.                 var ch = input[c];
  37.                 switch (ch)
  38.                 {
  39.                     case 'a':
  40.                     case 'e':
  41.                     case 'i':
  42.                         vCount++;
  43.                         break;
  44.                     case 'o':
  45.                     case 'u':
  46.                         vCount = vCount + 1;
  47.                         break;
  48.                 }
  49.             }
  50.  
  51.             return vCount - 1;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement