fr0stn1k

C#INFO2.0

Feb 12th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4.  
  5. namespace IMJunior
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.  
  12.             FilesCheck(new string[] {
  13.                 "words.txt",
  14.                 "in.txt"
  15.             });
  16.  
  17.             string[] list = File.ReadAllLines("words.txt");
  18.             string text = File.ReadAllText("in.txt");
  19.  
  20.             text = Filter(text, list);
  21.             string line = GenerateString(Console.WindowWidth, "-");
  22.             WriteColorLine(line);
  23.             WriteColorLine(text, ConsoleColor.Yellow);
  24.             WriteColorLine(line);
  25.  
  26.             File.WriteAllText("out.txt", text);
  27.         }
  28.  
  29.         static void FilesCheck(string[] paths)
  30.         {
  31.             for(int i = 0; i < paths.Length; i++)
  32.             {
  33.                 if (!File.Exists(paths[i]))
  34.                 {
  35.                     Console.WriteLine("Не найден файл - " + paths[i]);
  36.                     Console.ReadLine();
  37.                     Environment.Exit(1);
  38.                 }
  39.             }
  40.         }
  41.  
  42.         static string Filter(string text, string[] blackList)
  43.         {
  44.             for(int i = 0; i < blackList.Length; i++)
  45.             {
  46.                 text = text.Replace(blackList[i],
  47.                                     GenerateString(blackList[i].Length));
  48.             }
  49.             return text;
  50.         }
  51.  
  52.  
  53.         static string GenerateString(int length, string fuller = "#")
  54.         {
  55.             if (fuller.Length == 0)
  56.             {
  57.                 return "";
  58.             }
  59.  
  60.             string mask = "";
  61.             for (int j = 0; j < length; j += fuller.Length)
  62.             {
  63.                 mask += fuller;
  64.             }
  65.  
  66.             mask = mask.Substring(0, length);
  67.  
  68.             return mask;
  69.         }
  70.  
  71.         static void WriteColorLine(string message, ConsoleColor color = ConsoleColor.Red)
  72.         {
  73.             ConsoleColor old = Console.ForegroundColor;
  74.             Console.ForegroundColor = color;
  75.             Console.WriteLine(message);
  76.             Console.ForegroundColor = old;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment