Advertisement
Galina841130

Even Lines

Jan 17th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace EvenLines
  8. {
  9.     public class EvenLines
  10.     {
  11.         static void Main()
  12.         {
  13.             string inputFilePath = @"text.txt";
  14.  
  15.             Console.WriteLine(ProcessLines(inputFilePath));
  16.         }
  17.  
  18.         public static string ProcessLines(string inputFilePath)
  19.         {
  20.             using StreamReader reader = new StreamReader(inputFilePath);
  21.             char[] symbolArray = new char[] { '-', ',', '.', '!', '?' };
  22.             int counter = 0;
  23.             string line = reader.ReadLine();
  24.             StringBuilder sb = new StringBuilder();
  25.  
  26.             while (line != null)
  27.             {
  28.                 if (counter % 2 == 0)
  29.                 {
  30.                     foreach (char symbol in symbolArray)
  31.                     {
  32.                         if (line.Contains(symbol))
  33.                         {
  34.                             line = line.Replace(symbol, '@');
  35.                         }
  36.                     }
  37.                     string newLine = line.Split().Reverse().ToString();
  38.                     sb.AppendLine(newLine);
  39.                 }
  40.                 counter++;
  41.                 line = reader.ReadLine();
  42.             }
  43.             return sb.ToString().Trim();
  44.            
  45.         }
  46.  
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement