VXP

LB4_B

VXP
Apr 19th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2. ...
  3.         String имя_файла;
  4.         private void Form1_Load(object sender, EventArgs e)
  5.         {
  6.             var ТекущийКаталог = System.IO.Directory.GetCurrentDirectory();
  7.             имя_файла = ТекущийКаталог + @"\Text.txt";
  8.         }
  9.  
  10.         private void button1_Click(object sender, EventArgs e)
  11.         {
  12.             try
  13.             {
  14.                 var Кодировка = System.Text.Encoding.GetEncoding(1251);
  15.                 var Читатель = new System.IO.StreamReader(имя_файла, Кодировка);
  16.  
  17.                 /*
  18.                 string fullFile = Читатель.ReadToEnd();
  19.                 string[] sep = { "\r\n", "\n" };
  20.                 var lines = fullFile.Split(sep, StringSplitOptions.RemoveEmptyEntries);
  21.                 richTextBox1.Clear();
  22.                 foreach (string line in lines)
  23.                 {
  24.                     if (int.Parse(line) >= 10 && int.Parse(line) <= 99)
  25.                     {
  26.                         richTextBox1.Text += line + "\r\n";
  27.                     }
  28.                 }
  29.                 */
  30.  
  31.                 while (!Читатель.EndOfStream)
  32.                 {
  33.                     string line = Читатель.ReadLine();
  34.                     string[] numbers = Regex.Split(line, @"\D+");
  35.                     foreach (string value in numbers)
  36.                     {
  37.                         if (!string.IsNullOrEmpty(value))
  38.                         {
  39.                             if (int.Parse(value) >= 10 && int.Parse(value) <= 99)
  40.                             {
  41.                                 richTextBox1.Text += line + "\r\n";
  42.                             }
  43.                         }
  44.                     }
  45.                 }
  46.  
  47.                 Читатель.Close();
  48.             }
  49.             catch (System.IO.FileNotFoundException Ситуация)
  50.             {
  51.                 MessageBox.Show(Ситуация.Message + "\n" + "Нет такого файла", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  52.             }
  53.             catch (Exception Ситуация)
  54.             {
  55.                 MessageBox.Show(Ситуация.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  56.             }
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment