Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using static System.IO.File;
- using static System.Threading.Tasks.Parallel;
- namespace potokC
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string delimiters = " ,.!?-";
- var inputFilename = "text2.txt";
- var outputFilename = "output2.html";
- var dictionaryFilename = "dictionary2.txt";
- var dictionary = new HashSet<string>(ReadAllLines(dictionaryFilename));
- var textLines = ReadAllLines(inputFilename, Encoding.UTF8);
- var wordsToMark = new ConcurrentBag<string>();
- for (var i = 0; i < textLines.Length; i++)
- {
- var words = textLines[i].Split(delimiters.ToCharArray(), options: StringSplitOptions.RemoveEmptyEntries)
- .Distinct()
- .ToArray();
- ForEach(words, (word) =>
- {
- if (dictionary.Contains(word))
- wordsToMark.Add(word);
- });
- foreach (var word in wordsToMark)
- textLines[i] = textLines[i].Replace(word, MarkWord(word));
- }
- WriteAllLines(outputFilename, textLines, Encoding.UTF8);
- }
- static string MarkWord(string word) => $"<b><i>{word}</b></i>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment