1
I have a problem reading a txt file that has its columns separated by comma but also has monetary values that are being cut and should not, because they are in quotes. Follow example of the line:
Nome, Idade, Valor a receber, Valor pendente, descricao
Teste, 25, "1.234,30", "987,90", teste
after having read the file
string[] todasLinhas = File.ReadAllLines(arquivo, Encoding.GetEncoding("iso-8859-1"));
I try to cut by comma
foreach (string linha in todasLinhas)
{
string[] colunas = linha.Split(',');
}
the result is this way:
Teste
25
"1234
30"
"987
90"
teste
Is there any way to make Split not cut when the character is in quotes? or if there is any other solution that you can share?
Daniel Dutra, thank you for the answer, but it happens that the lines do not have space after the comma, so the first option will not serve, despite being a good solution. The second option did not work. Is it for the same reason?
– Iago Correia Guimarães
Yes, it is at least reason. The second solution without spaces will only split in comma before special character.
– Daniel Dutra
It includes a solution in case there are no spaces. The solution is big and ugly, but it works. Then I try to improve it.
– Daniel Dutra