Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that replaces all occurrences of the substring "start" with the substring "finish"
- //in a text file. Ensure it will work with large files (e.g. 100 MB).
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- class ReplaceStartWithFinish7
- {
- static void Main()
- {
- string start = "start";
- string finish = "finish";
- StreamReader read = new StreamReader("../../input.txt");
- StreamWriter write = new StreamWriter("../../input2.txt");
- string line = "";
- using (read)
- {
- using (write)
- {
- line = read.ReadLine().ToLower();
- while (line != null)
- {
- line = line.Replace(start, finish);
- write.WriteLine(line);
- line = read.ReadLine();
- }
- }
- }
- File.Replace("../../input2.txt", "../../input.txt", "../../backup.txt");
- // if you want to delete backup file uncomment next row
- //File.Delete("../../backup.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement