Ciao a tutti,
sto scrivendo un programma che mi legge un file csv e ne crea un secondo con tutte le informazioni del primo ma con qualche modifica.
codice:
Dim NomeFile As String = "C:\file1.csv"
Dim NomeFileNew As String = "C:\file2.csv"
FileOpen(FileNumber, NomeFile, OpenMode.Input)
FileOpen(FileNumber2, NomeFileNew, OpenMode.Output)
Do Until (EOF(FileNumber))
' Read a line from file
Dim Text As String = LineInput(FileNumber)
' Split line at commas
Dim Values() As String = Split(Text, ";")
If i = 0 Then
WriteLine(FileNumber2, Text)
Else
If Values(3) <> "" Then
Select Case Values(3).Substring(3, 3)
Case "GEN"
Values(3) = Values(3).Substring(0, 3) & "JAN" & Values(3).Substring(6, 3)
Case "FEB"
Values(3) = Values(3).Substring(0, 3) & "FEB" & Values(3).Substring(6, 3)
Case "MAR"
Values(3) = Values(3).Substring(0, 3) & "MAR" & Values(3).Substring(6, 3)
Case "APR"
Values(3) = Values(3).Substring(0, 3) & "APR" & Values(3).Substring(6, 3)
Case "MAG"
Values(3) = Values(3).Substring(0, 3) & "MAY" & Values(3).Substring(6, 3)
Case "GIU"
Values(3) = Values(3).Substring(0, 3) & "JUN" & Values(3).Substring(6, 3)
Case "LUG"
Values(3) = Values(3).Substring(0, 3) & "JUL" & Values(3).Substring(6, 3)
Case "AGO"
Values(3) = Values(3).Substring(0, 3) & "AUG" & Values(3).Substring(6, 3)
Case "SET"
Values(3) = Values(3).Substring(0, 3) & "SEP" & Values(3).Substring(6, 3)
Case "OTT"
Values(3) = Values(3).Substring(0, 3) & "OCT" & Values(3).Substring(6, 3)
Case "NOV"
Values(3) = Values(3).Substring(0, 3) & "NOV" & Values(3).Substring(6, 3)
Case "DIC"
Values(3) = Values(3).Substring(0, 3) & "DEC" & Values(3).Substring(6, 3)
End Select
End If
j = 0
For Each str In Values
If j = 0 Then
Text = str
Else
Text = Text & ";" & str
End If
j = j + 1
Next
WriteLine(FileNumber2, Text)
End If
i = i + 1
Loop
FileClose(FileNumber)
FileClose(FileNumber2)
Il mio problema è che la stringa finale che viene scritta dalla writeline contine i doppi apici all'inizio e alla fine della stessa e questo non mi consente di effettuare l'importazione del file in un DB Access.
Ecco un piccolo esempio di come si presenta il file csv:
CD_PRAT;CE_ZONA;DE_ZONE;DA_CREA;CE_RSOC;
123456879;ZONA1;NORD-OVEST (MI+IVR);05-GEN-12;Azienda xxx
il nuovo file si presenta in questa maniera
"CD_PRAT;CE_ZONA;DE_ZONE;DA_CREA;CE_RSOC"
"123456879;ZONA1;NORD-OVEST (MI+IVR);05-JAN-12;Azienda xxx
Sto impazzendo!!!!!!!
Ho provato a copiare anche dalla posizione 1 alla len-1 della stringa ma mi tronca il primo carattere, come è possibile che vengano copiati i doppi apici anche se non sono presenti nella stringa?
Grazie in anticipo
Andrea