Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _01._Even_Lines
  7. {
  8. class StartUp
  9. {
  10. static void Main(string[] args)
  11. {
  12. StreamReader streamReader = new StreamReader("./text.txt");
  13.  
  14. int counter = 0;
  15.  
  16. while (!streamReader.EndOfStream)
  17. {
  18. string line = streamReader.ReadLine();
  19.  
  20. if(line == null)
  21. {
  22. break;
  23. }
  24.  
  25. if(counter % 2 == 0)
  26. {
  27. char[] charsToReplace = new char[] { '-', ',', '.', '!', '?' };
  28.  
  29. line = ReplaceChars(charsToReplace, '@', line);
  30. line = ReverseWordsOrder(line);
  31.  
  32. Console.WriteLine(line);
  33. }
  34.  
  35. counter++;
  36. }
  37. }
  38.  
  39. private static string ReverseWordsOrder(string line)
  40. {
  41. line = String.Join(" ", line.Split(" ").Reverse());
  42. return line;
  43. }
  44.  
  45. static string ReplaceChars(char[] charsToReplace, char replacement, string str)
  46. {
  47. StringBuilder sb = new StringBuilder();
  48.  
  49. for (int i = 0; i < str.Length; i++)
  50. {
  51. if (charsToReplace.Contains(str[i]))
  52. {
  53. sb.Append(replacement);
  54. }
  55. else
  56. {
  57. sb.Append(str[i]);
  58. }
  59. }
  60.  
  61. return sb.ToString().TrimEnd();
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement