Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace ConsoleApp1
- {
- class Program
- {
- static void PaprastiKomentarai(string fv, string fa)
- {
- string[] lines = File.ReadAllLines(fv);
- using (var fr = File.CreateText(fa))
- {
- foreach (string line in lines)
- {
- string nauja = line;
- for (int i = 0; i < line.Length - 1; i++)
- {
- if (line[i] == '/' && line[i + 1] == '/')
- {
- nauja = line.Remove(i);
- }
- }
- if(nauja.Trim() != "") fr.WriteLine(nauja);
- }
- }
- }
- static void SudetingiKomentarai(string fv, string fd)
- {
- string text = File.ReadAllText(fv);
- using (var fr = File.CreateText(fd))
- {
- bool start = false;
- bool end = false;
- int k = 0;
- bool count = false;
- bool comment = false;
- int index1 = -1;
- for (int i = 1; i < text.Length; i++)
- {
- if (text[i-1] == '"') comment = true;
- if (text[i] == '"' && comment) comment = false;
- end = false;
- if (text[i-1] == '/' && text[i] == '*' && !start && !comment)
- {
- index1 = i - 1;
- start = true;
- count = true;
- }
- if (count) k++;
- if (text[i - 1] == '*' && text[i] == '/' && !comment)
- {
- end = true;
- text = text.Remove(index1, k+1);
- count = false;
- k = 0;
- start = false;
- i = 0;
- }
- }
- if (start && !end)
- {
- k = text.Length - index1;
- text = text.Remove(index1, k);
- }
- fr.Write(text);
- }
- }
- static void Main(string[] args)
- {
- const string CFd = "Duomenys.txt";
- const string CFr = "Rezultatai.txt";
- const string CFa = "Analize.txt";
- PaprastiKomentarai(CFd, CFa);
- SudetingiKomentarai(CFa, CFr);
- Console.WriteLine("Finished");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement