Advertisement
Guest User

Untitled

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