elena1234

LineNumbers- with stream and counter

Jan 16th, 2021 (edited)
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace LineNumbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             using(var reader=new StreamReader("input.txt"))
  12.             {
  13.                 using (var writer = new StreamWriter("output.txt"))
  14.                 {
  15.                     int lineCounter = 1;
  16.                     while (!reader.EndOfStream)
  17.                     {
  18.                         var line = reader.ReadLine();
  19.                         var lineWithoutSpace = line.Replace(" ", "");
  20.                         var listWithChars = lineWithoutSpace.ToCharArray().ToList();                      
  21.                         int sumLetter = 0;
  22.                         int sumPunctuationMarks = 0;
  23.                         foreach (var symbol in listWithChars)
  24.                         {
  25.                             if (char.IsLetter(symbol))
  26.                             {
  27.                                 sumLetter++;
  28.                             }
  29.  
  30.                             else
  31.                             {
  32.                                 sumPunctuationMarks++;
  33.                             }
  34.                         }
  35.  
  36.                         writer.WriteLine($"Line {lineCounter}:{line}({sumLetter})({sumPunctuationMarks})");
  37.                         listWithChars.Clear();
  38.                         lineCounter++;
  39.                     }                
  40.                 }
  41.             }            
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment