Advertisement
VXP

LB4

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