[RESOLVED] Need to join lines with just LF at the end
I've a text file where some lines end with vbLf and I need to join them to become one.
I already tried several approaches but none gave the result I need (read a line and writing a new one in a new file replacing the vbLf, loading all the lines to a string and replace the vbLf with "", etc...).
It comes like this
and I need to change to this
CEE;AGO;;DBAGOP1;TBAGOCOB;P;"SELECT B.* LF
FROM DB2PSYS.TBIDRF_MIG A, LF
DB2PSYS.TBAGOCOB B LF
WHERE B.IDRBES = A.IDRBES";;OK;;In;108.509;CRLF
and I need it to be like this
CEE;AGO;;DBAGOP1;TBAGOCOB;P;"SELECT B.* FROM DB2PSYS.TBIDRF_MIG A, DB2PSYS.TBAGOCOB B WHERE B.IDRBES = A.IDRBES";;OK;;In;108.509;CRLF
The approaches you tried should work if coded properly. Post the code from those attempts and maybe we can help.
One highly inefficient but simple to implement approach would be:
-Read file contents into one String
-Replace vbLF with empty string
-Replace vbCR with vbCRLF
Last edited by OptionBase1; Aug 2nd, 2024 at 03:23 PM.
I can't access the attachment, really not sure how they are being replaced with a vbCrLF as nothing in the code is adding any vbCrLf characters. I just updated the code above to write the file out...
Code:
Dim data = File.ReadAllText("CSV_LOAD.csv")
Dim regex = New Regex("(?<!\r)\n")
Dim cleanData = regex.Replace(data, "")
File.WriteAllText("CSV_OUT.csv", cleanData)
and the lines certainly aren't looking like they contain any extra vbCrLf, I have attached a screenshot with the original version on the left and the updated version on the right.
I can't access the attachment, really not sure how they are being replaced with a vbCrLF as nothing in the code is adding any vbCrLf characters. I just updated the code above to write the file out...
Code:
Dim data = File.ReadAllText("CSV_LOAD.csv")
Dim regex = New Regex("(?<!\r)\n")
Dim cleanData = regex.Replace(data, "")
File.WriteAllText("CSV_OUT.csv", cleanData)
and the lines certainly aren't looking like they contain any extra vbCrLf, I have attached a screenshot with the original version on the left and the updated version on the right.