Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlTypes;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- namespace _4._1
- {
- class Program
- {
- static void Main(string[] args)
- {
- const string CFd = "..\\..\\Duomenys.txt";
- const string CFr = "..\\..\\Rezultatai.txt";
- const string CFa = "..\\..\\Analize.txt";
- Apdoroti(CFd, CFr, CFa);
- }
- //------------------------------------------------------------
- /** Skaito, analizuoja ir rašo į skirtingus failus.
- @param fv - duomenų failo vardas
- @param fvr - rezultatų failo vardas
- @param fa - analizės failo vardas */
- static void Apdoroti(string fv, string fvr, string fa)
- {
- string[] lines = File.ReadAllLines(fv, Encoding.GetEncoding(1257));
- using (var fr = File.CreateText(fvr))
- {
- using (var far = File.CreateText(fa))
- {
- foreach (string line in lines)
- {
- string x = line;
- Console.WriteLine(x);
- bool arYra = true;
- if (x.Length > 0)
- {
- for (int i = 0; i < line.Length - 1; i++)
- {
- if (line[i] == '/' && line[i + 1] == '*')
- {
- arYra = false;
- }
- if (line[i] == '*' && line[i + 1] == '/')
- {
- arYra = true;
- }
- if (arYra == false)
- {
- x = line.Remove(i);
- }
- }
- }
- if (x.Length > 0)
- {
- string nauja = x;
- if (BeKomentaru(x, out nauja))
- far.WriteLine(x);
- if (nauja.Length > 0)
- fr.WriteLine(nauja);
- }
- else
- fr.WriteLine(x);
- }
- }
- }
- }
- //------------------------------------------------------------
- /** Pašalina iš eilutės komentarus ir grąžina požymį, ar šalino.
- @param line - eilutė su komentarais
- @param nauja - eilutė be komentarų */
- static bool BeKomentaru(string line, out string nauja)
- {
- nauja = line;
- for (int i = 0; i < line.Length - 1; i++)
- {
- if (line[i] == '/' && line[i + 1] == '/')
- {
- nauja = line.Remove(i);
- return true;
- }
- }
- return false;
- }
- //------------------------------------------------------------
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement