Advertisement
desislava_topuzakova

02. Line Numbers

May 28th, 2022
805
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace LineNumbers
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.IO;
  6.     using System.Linq;
  7.  
  8.     public class LineNumbers
  9.     {
  10.         static void Main()
  11.         {
  12.             string inputFilePath = @"..\..\..\text.txt"; // файл за четене
  13.             string outputFilePath = @"..\..\..\output.txt"; //файл за писане
  14.  
  15.             ProcessLines(inputFilePath, outputFilePath);
  16.         }
  17.  
  18.         public static void ProcessLines(string inputFilePath, string outputFilePath)
  19.         {
  20.             string[] lines = File.ReadAllLines(inputFilePath);
  21.             int count = 0;
  22.             List<string> outputLines = new List<string>();
  23.  
  24.             foreach(string line in lines)
  25.             {
  26.                 //"-I was quick to judge him, but it wasn't his fault."
  27.                 count++;
  28.                
  29.                 //2. броим буквите
  30.                 int countLetters = line.Count(char.IsLetter); //37
  31.                 //3. броим символите, които са пунктуационни знаци
  32.                 int countSymbol = line.Count(char.IsPunctuation); //4
  33.                 //1. номер на реда
  34.                 string modifiedLine = $"Line {count}: {line} ({countLetters})({countSymbol})";
  35.                 //"Line 1: -I was quick to judge him, but it wasn't his fault. (37)(4)"
  36.                 outputLines.Add(modifiedLine);
  37.  
  38.             }
  39.             File.WriteAllLines(outputFilePath, outputLines);
  40.         }
  41.     }
  42. }
  43.  
Advertisement
RAW Paste Data Copied
Advertisement