Advertisement
sangueroots

C# Dividi Arquivo Txt

Mar 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. class SQG
  2. {
  3.     public string Grupo {get;set;}
  4.     public string Cota {get;set;}
  5.     public string NoParcela {get; set;}
  6.     public double ValorLiberado {get; set;}
  7. }
  8.  
  9. void Main()
  10. {
  11.     double valorLiberadoOut;
  12.     int counter = 0;
  13.     string line;
  14.     var ListReader = new List<SQG>();
  15.     using(StreamReader reader = new StreamReader(Path.Combine("D:\\Wiz\\SQG\\ENVIO_0101_COB008_RelDistCobranca16032019.txt")))
  16.     {
  17.         using(StreamWriter fileFiltered = new StreamWriter(Path.Combine("D:\\Wiz\\SQG\\OutPutFileFiltered.txt")))
  18.         {
  19.             using(StreamWriter fileUpdated = new StreamWriter(Path.Combine("D:\\Wiz\\SQG\\OutPutFileUpdated.txt")))
  20.             {
  21.            
  22.                 while ((line = reader.ReadLine()) != null) {
  23.                     if(counter != 0)
  24.                     {
  25.                         var addRecord = new SQG
  26.                         {
  27.                             Grupo = line.Substring(0, 6),
  28.                             Cota = line.Substring(6,6),
  29.                             NoParcela = line.Substring(648,3),
  30.                             ValorLiberado = double.TryParse(line.Substring(655,9), out valorLiberadoOut) ? valorLiberadoOut : 0.00
  31.                         };
  32.                        
  33.                         if(addRecord.ValorLiberado >= 500000.00){
  34.                             fileFiltered.WriteLine(line);
  35.                         }else{
  36.                             fileUpdated.WriteLine(line);
  37.                         }
  38.                         ListReader.Add(addRecord); 
  39.                     }
  40.                     counter++;
  41.                 }
  42.                 reader.Close();
  43.                 fileUpdated.Close();
  44.                 fileFiltered.Close();
  45.             }
  46.             Console.WriteLine(ListReader);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement