EMILIA_ASANOVA

WorkWithFiles

Nov 2nd, 2022
1,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace WorkWithFile
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string fname = @"C:\Users\user\source\repos\Practice\WorkWithFile\MyFile.txt";
  11.             string result = @"C:\Users\user\source\repos\Practice\WorkWithFile\Result.txt";
  12.  
  13.             using (StreamReader streamReader = new StreamReader(fname))
  14.             {
  15.                 using (StreamWriter streamWriter = new StreamWriter(result))
  16.                 {
  17.                     char symbol = (char)streamReader.Read();
  18.  
  19.                     while (!streamReader.EndOfStream)
  20.                     {
  21.                         if (!char.IsPunctuation(symbol))
  22.                         {
  23.                             streamWriter.Write(symbol);
  24.                         }
  25.  
  26.                         symbol = (char)streamReader.Read();
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             File.Delete(fname);
  32.             File.Move(result, fname);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment