Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 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. Console.WriteLine(line);
  37. bool exist = true;
  38. if (line.Length > 0)
  39. {
  40. for (int i = 0; i < line.Length - 1; i++)
  41. {
  42. if (line[i] == '/' && line[i + 1] == '*')
  43. {
  44. exist = false;
  45. }
  46. if (line[i] == '*' && line[i + 1] == '/')
  47. {
  48. exist = true;
  49. }
  50. if (exist == false)
  51. {
  52. line.Remove(i);
  53. }
  54. }
  55. }
  56.  
  57. if (line.Length > 0)
  58. {
  59. string nauja = line;
  60. if (BeKomentaru(line, out nauja))
  61. far.WriteLine(line);
  62. if (nauja.Length > 0)
  63. fr.WriteLine(nauja);
  64. }
  65. else
  66. fr.WriteLine(line);
  67. }
  68. }
  69. }
  70. }
  71. //------------------------------------------------------------
  72. /** Pašalina iš eilutės komentarus ir grąžina požymį, ar šalino.
  73. @param line - eilutė su komentarais
  74. @param nauja - eilutė be komentarų */
  75. static bool BeKomentaru(string line, out string nauja)
  76. {
  77. nauja = line;
  78. for (int i = 0; i < line.Length - 1; i++)
  79. {
  80. if (line[i] == '/' && line[i + 1] == '/')
  81. {
  82. nauja = line.Remove(i);
  83. return true;
  84. }
  85.  
  86. }
  87. return false;
  88. }
  89. //------------------------------------------------------------
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement