Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace FileIO
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. Console.WriteLine(amountOfWords("the", new StreamReader(@"C:\Users\Sebas\OneDrive\Dokumenter\Visual Studio 2017\Projects\FileIO\The writings of Abraham Lincoln.txt")));
  16. Console.ReadLine();
  17. }
  18.  
  19. private static int amountOfWords(string word, StreamReader sr)
  20. {
  21. int amountUsed = 0;
  22. using (sr)
  23. {
  24. String text = sr.ReadToEnd();
  25. string regexPattern = @"[Tt]he";
  26. amountUsed = Regex.Matches(text, regexPattern).Count;
  27. }
  28.  
  29. return amountUsed;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement