1
Read and save the file
public void LereGravar()
{
Console.WriteLine($"{DateTime.Now.ToString()} - Processamento Iniciado, Lendo Arquivo");
//Procura dentro da Pasta
DirectoryInfo Dir = new DirectoryInfo(LerArquivos);
FileInfo[] Files = Dir.GetFiles("*", SearchOption.AllDirectories);
var conteudoArquivo = new List<ArquivoTxt>();
foreach (System.IO.FileInfo fi in Dir.GetFiles())
{
using (StreamReader leitor = fi.OpenText())
{
while (!leitor.EndOfStream)
{
var linha = new ArquivoTxt();
linha.Linha = leitor.ReadLine();
conteudoArquivo.Add(linha);
}
}
StreamWriter sw = new StreamWriter(Carteira_Vendas, true, System.Text.Encoding.GetEncoding("UTF-8"));
conteudoArquivo = conteudoArquivo.Where(_ => _.Linha.StartsWith("|") &&
_.Linha.Substring(0, 2) != "|O" &&
_.Linha.Substring(0, 2) != "|-" &&
_.Linha.Substring(0, 2) != "|C" &&
_.Linha.Substring(0, 2) != "|I" &&
_.Linha.Substring(0, 2) != "|T" &&
_.Linha.Substring(0, 2) != "| " &&
_.Linha.Substring(0, 2) != "|R" &&
_.Linha.Substring(0, 2) != "|D" &&
_.Linha.Substring(0, 2) != "|E").ToList();
Console.WriteLine($"{DateTime.Now.ToString()} - Processamento finalizado");
foreach (var item in conteudoArquivo)
{
string[] linha = item.Linha.Split('|');
string ordemVenda = linha[1].Trim();
sw.WriteLine(TiraAcentuacao(item.Linha));
};
sw.Close();
}
}
You should remove the seats
static string TiraAcentuacao(string StringAcentuada)
{
if (string.IsNullOrEmpty(StringAcentuada.Trim()))
return string.Empty;
else
{
byte[] array = Encoding.GetEncoding("iso-8859-8").GetBytes(StringAcentuada);
return Encoding.UTF8.GetString(array);
}
}
Return of the Line I receive
|2021552949 |000018 |0001 |MTO |ZNOR |1182042 |3A ALUMINIO INDUSTRIA E COMERCIO EI|1182042 |3A ALUMINIO INDUSTRIA E COMERCIO EI|6155211 |ES E13152 6063 T5 6000 N-CG |4500017089 | 1.381,000 |KG | 3.908,230 | 3.908,230 | 0,000 |CN | 2.614,375 | 0,000 | 0,000 | 0,000 |26.12.2017 |2020 |C |30.06.2018|24.08.2018 |24.08.2018 |22.08.2018 |23.08.2018 | |2100 |OUTROS CC |ESN0300 |EXTRUDADO NATURAL |Conjuga?? o Load | |SIM |Extruded |BLEANDROGG |2SP156 |SP-ALUM? NIO/SP-JANDIRA |CIF-Jandira - SP | 0,000 | 6.000,00|2020 |
My return is (?) in the seats of the seats, what could I do for him to record the accent or simply ignore it.
If you just do the
sw.WriteLine(item.Linha);
does not record with accents?– João Martins
No, I’ve tried, he replaces the seat for a question mark.
– Guilherme Palange
I did the test here and it worked normal. I don’t know much about encoding, but maybe it’s this transition that’s causing the problem. Try using this method: https://dotnetfiddle.net/3VwlPV
– Francisco