Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlTypes;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Text.RegularExpressions;
  9.  
  10.  
  11. namespace _4._1
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. const string CFd = "..\\..\\Duomenys.txt";
  18. const string CFr = "..\\..\\Rezultatai.txt";
  19. const string CFa = "..\\..\\Analize.txt";
  20. Apdoroti(CFd, CFr, CFa);
  21. }
  22. //------------------------------------------------------------
  23. /** Skaito, analizuoja ir rašo į skirtingus failus.
  24. @param fv - duomenų failo vardas
  25. @param fvr - rezultatų failo vardas
  26. @param fa - analizės failo vardas */
  27. static void Apdoroti(string fv, string fvr, string fa)
  28. {
  29. string[] lines = File.ReadAllLines(fv, Encoding.GetEncoding(1257));
  30. using (var fr = File.CreateText(fvr))
  31. {
  32. using (var far = File.CreateText(fa))
  33. {
  34. foreach (string line in lines)
  35. {
  36. string x = line;
  37. Console.WriteLine(x);
  38. bool arYra = true;
  39. if (x.Length > 0)
  40. {
  41. for (int i = 0; i < line.Length - 1; i++)
  42. {
  43. if (line[i] == '/' && line[i + 1] == '*')
  44. {
  45. arYra = false;
  46. }
  47. if (line[i] == '*' && line[i + 1] == '/')
  48. {
  49. arYra = true;
  50. }
  51. if (arYra == false)
  52. {
  53. x = line.Remove(i);
  54. }
  55. }
  56. }
  57.  
  58. if (x.Length > 0)
  59. {
  60. string nauja = x;
  61. if (BeKomentaru(x, out nauja))
  62. far.WriteLine(x);
  63. if (nauja.Length > 0)
  64. fr.WriteLine(nauja);
  65. }
  66. else
  67. fr.WriteLine(x);
  68. }
  69. }
  70. }
  71. }
  72. //------------------------------------------------------------
  73. /** Pašalina iš eilutės komentarus ir grąžina požymį, ar šalino.
  74. @param line - eilutė su komentarais
  75. @param nauja - eilutė be komentarų */
  76. static bool BeKomentaru(string line, out string nauja)
  77. {
  78. nauja = line;
  79. for (int i = 0; i < line.Length - 1; i++)
  80. {
  81. if (line[i] == '/' && line[i + 1] == '/')
  82. {
  83. nauja = line.Remove(i);
  84. return true;
  85. }
  86.  
  87. }
  88. return false;
  89. }
  90. //------------------------------------------------------------
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement