3
I have a code that reads a CSV and saves the information in the database, but I ended up getting a CSV "different" than what I’m used to reading. This CSV come with double quotes in the information.
Ex: "0";"20151109";"171729";"20151101";"20151106";"V3.0";"00";"20151109171729";"000001"
There is a possibility to make a replace
? The function remove
that I tried it just removes the first quotes. (if there is a possibility to do the remove also, I’d like an example as it didn’t work properly here). I’ll show you a piece of what is done.
if (Directory.Exists(pasta_tempFisico))
{
using (sr)
{
while (!sr.EndOfStream)
{
sline = sr.ReadLine();
if (sline.Substring(1, 1) == "0")
{
string[] DadosRPS = sline.Split(';');
dtCriacaoArqHd = DateTime.Parse(DadosRPS[1].Substring(1, 4) + "/" + DadosRPS[1].Substring(5, 2) + "/" + DadosRPS[1].Substring(7, 2) + " " + DadosRPS[2].Substring(1, 2) + ":" + DadosRPS[2].Substring(3, 2) + ":" + DadosRPS[2].Substring(5, 2));
dtInicialHd = DateTime.Parse(DadosRPS[3].Substring(1, 4) + "/" + DadosRPS[3].Substring(5, 2) + "/" + DadosRPS[3].Substring(7, 2));
dtFinalHd = DateTime.Parse(DadosRPS[4].Substring(1, 4) + "/" + DadosRPS[4].Substring(5, 2) + "/" + DadosRPS[4].Substring(7, 2));
VersaoHd = Convert.ToString(DadosRPS[5]);
codIdnRedeHd = Convert.ToInt32(DadosRPS[6]);
numSeqArqHd = Convert.ToInt32(DadosRPS[7]);
numSeqRegArqHd = Convert.ToInt32(DadosRPS[8]);
}
Obs: the sline.Substring(1, 1)
is thus only by test, since in the removal would be (0.1) on account of quotation marks.
could demonstrate an example of code? Just to make it clearer even to others who have the same doubt, if your solution is useful to third parties. I thank you already! :)
– Daniel Nicodemos