Advertisement
Guest User

my solution

a guest
Nov 19th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. [Test]
  2.         public void TestExercise4()
  3.         {
  4.             Programmeren2Tests.Chapter12Test.TestExercise4(Exercise4);
  5.         }
  6.  
  7.         public static int Exercise4()
  8.         {
  9.             int count = 0;
  10.             foreach (string str in LoadAliceInWonderland())
  11.                 if (str == "queen")
  12.                     count++;
  13.             return count;
  14.             //throw new NotImplementedException();
  15.         }
  16.  
  17.         //load the book (from file) and return it as a string array
  18.         public static string[] LoadAliceInWonderland()
  19.         {
  20.             string aliceFile = Path.Combine(Environment.CurrentDirectory, "bestanden\\alice_in_wonderland.txt");
  21.             string text = File.ReadAllText(aliceFile).ToLower();
  22.             string[] words = removeUselessValues(text).Split();
  23.             return words;
  24.         }
  25.  
  26.         public static string removeUselessValues(string s)
  27.         {
  28.             string result = "";
  29.             foreach (char c in s)
  30.                 result += (c.Equals('q') || c.Equals('u') || c.Equals('e') || c.Equals('n')) ? c : ' ';
  31.             return result;
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement