Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace FileIO
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(amountOfWords("the", new StreamReader(@"C:\Users\Sebas\OneDrive\Dokumenter\Visual Studio 2017\Projects\FileIO\The writings of Abraham Lincoln.txt")));
- Console.ReadLine();
- }
- private static int amountOfWords(string word, StreamReader sr)
- {
- int amountUsed = 0;
- using (sr)
- {
- String text = sr.ReadToEnd();
- string regexPattern = @"[Tt]he";
- amountUsed = Regex.Matches(text, regexPattern).Count;
- }
- return amountUsed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement