Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- //Write a program that reads a text file and inserts line numbers in front of each of its lines.
- //The result should be written to another text file.
- class InsertLineNumbers
- {
- static void Main()
- {
- using (StreamWriter writer = new StreamWriter("new.txt"))
- using (StreamReader reader = new StreamReader("streamreader.txt"))
- {
- StringBuilder builder = new StringBuilder();
- string line;
- int lineNum = 1;
- while ((line = reader.ReadLine()) != null)
- {
- builder.Append(lineNum).Append(". ").Append(line);
- writer.WriteLine(builder.ToString());
- builder.Clear();
- lineNum++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement