From 0bd9e8f9ef9e5273c0814ba846c2569049b6de38 Mon Sep 17 00:00:00 2001 From: LinuxOW Date: Wed, 30 Jul 2025 15:15:26 +0100 Subject: [PATCH] Create adafdsa --- TestProcessing-1/adafdsa | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 TestProcessing-1/adafdsa diff --git a/TestProcessing-1/adafdsa b/TestProcessing-1/adafdsa new file mode 100644 index 0000000..235c645 --- /dev/null +++ b/TestProcessing-1/adafdsa @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace TestProcessing_1 +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Please enter the file path:"); + var filePath = Console.ReadLine(); + + if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath)) + { + Console.WriteLine("Invalid file path. Please try again."); + return; + } + + try + { + var wordCount = CountWordsInFile(filePath); + PrintResults(wordCount); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } + + private static Dictionary CountWordsInFile(string filePath) + { + var wordCount = new Dictionary(); + var lines = File.ReadAllLines(filePath); + + foreach (var line in lines) + { + var cleanedLine = Regex.Replace(line, @"[^\w\s]", "").ToLower(); + var words = cleanedLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + foreach (var word in words) + { + if (wordCount.ContainsKey(word)) + wordCount[word]++; + else + wordCount[word] = 1; + } + } + + return wordCount; + } + + private static void PrintResults(Dictionary wordCount) + { + Console.WriteLine("Done"); + foreach (var entry in wordCount) + { + Console.WriteLine($"{entry.Key}: {entry.Value}"); + } + Console.WriteLine($"Unique words count: {wordCount.Count}"); + } + } +}