Advertisement
hristo_bratanov

Insert line numbers in front of each line in text file

Jan 23rd, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4.  
  5. class InsertLineNumbers
  6. {
  7.     static void Main()
  8.     {
  9.         StreamReader reader = new StreamReader("subs.txt", Encoding.GetEncoding("windows-1251"));
  10.         using (reader)
  11.         {
  12.             int count = 1;
  13.             string line;
  14.             StreamWriter writer = new StreamWriter("subsIndexed.txt", false, Encoding.GetEncoding("windows-1251"));
  15.             using (writer)
  16.             {
  17.                 while ((line = reader.ReadLine()) != null)
  18.                 {
  19.                     writer.Write("line {0}: ", count);
  20.                     writer.WriteLine(line);
  21.                     count++;
  22.                 }
  23.  
  24.             }
  25.            
  26.         }
  27.  
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement