Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4.  
  5. namespace ProbaForms
  6. {
  7.     static class Program
  8.     {
  9.         [STAThread]
  10.         static void Main(string[] args)
  11.         {
  12.         OpenFileDialog fileDialog = new OpenFileDialog() { Filter = "Text Files (.txt)|*.txt" };
  13.             fileDialog.ShowDialog();
  14.  
  15.             if (!File.Exists(fileDialog.FileName))
  16.             {
  17.                 Console.WriteLine("Selected file does not exist anymore.");
  18.             }
  19.             else
  20.             {
  21.                 string line = String.Empty;
  22.                 char[] delimiters = new char[] { ' ' };
  23.                 int outputCnt = 0;
  24.  
  25.                 StreamReader file = new StreamReader(fileDialog.FileName);
  26.                 while (((line = file.ReadLine()) != null) && (line.Length != 0))
  27.                 {
  28.                     line = String.Join(" ", line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries));
  29.  
  30.                     for (int i = 0; i < line.Length; i++)
  31.                     {
  32.                         ++outputCnt;
  33.                         Console.Write(line[i]);
  34.  
  35.                         if (((outputCnt % 30 == 0) && (i != (line.Length - 1))) || (i == line.Length - 1))
  36.                         {
  37.                             Console.Write("\n");
  38.                             outputCnt = 0;
  39.                         }
  40.                     }
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine("\nPress 'Enter' to exit.");
  45.             Console.ReadLine();
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement