Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Text.RegularExpressions;
  8.  
  9.  
  10. namespace REGEXP
  11. {
  12.     /// <summary>
  13.     /// РЕГУЛЯРНЫЕ ВЫРАЖЕНИЯ ВАРИАНТ 3
  14.     /// </summary>
  15.     class Program
  16.     {
  17.         static string ValidateInputFile()
  18.         {
  19.             string s;
  20.             while (true)
  21.             {
  22.  
  23.                 Console.Write("Введите имя входного файла : ");
  24.                 try
  25.                 {
  26.  
  27.                     s = Console.ReadLine();
  28.                     StreamReader sr = new StreamReader(s);
  29.                     Console.WriteLine("Файл найден!");
  30.                     break;
  31.  
  32.                 }
  33.                 catch (Exception)
  34.                 {
  35.                     Console.WriteLine("Неверное имя файла или такого файла не существует! Повторите попытку еще раз...");
  36.                 }
  37.             }
  38.             return s;
  39.         }
  40.  
  41.         static void Main(string[] args)
  42.         {
  43.             string inputfilename = ValidateInputFile();
  44.             Console.Write("Введите имя выходного файла : ");
  45.             string outputfilename = Console.ReadLine();
  46.  
  47.             string pattern = @"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
  48.  
  49.  
  50.             using (StreamReader sr = new StreamReader(inputfilename))
  51.             {
  52.                 using (StreamWriter sw = new StreamWriter(outputfilename))
  53.                 {
  54.                     string s;
  55.                     while (!sr.EndOfStream)
  56.                     {
  57.                         s = sr.ReadLine();
  58.                         Match M = Regex.Match(s, pattern);
  59.                         if (M == Match.Empty)
  60.                         {
  61.  
  62.                             sw.WriteLine(s);
  63.  
  64.                         }
  65.                     }
  66.                 }
  67.             }
  68.  
  69.             Console.WriteLine("Файл обработан!");
  70.  
  71.         }
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement