Re: End of Line

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Sep 8, 12:38 pm, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxxxxxxxxxxxxxxxx> wrote:
"Odd" <audrey....@xxxxxxxxx> wrote in message

news:3ccd9e18-9354-4c57-8ec5-4298bc9be107@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 8, 11:45 am, "Richard Mueller [MVP]" <rlmueller-





nos...@xxxxxxxxxxxxxxxxxxxx> wrote:
"Odd" <audrey....@xxxxxxxxx> wrote in message

news:8a2b8b75-480a-4315-88d4-849b5ceb3c96@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi everyone,

I have a .csv file where certain fields have carriage returns/new line
feeds. Because of such, I cannot properly import my file. Hence, I
wrote the following script and while it removes the carriage returns/
new line feeds through the file, it ALSO removes the END OF LINE
carriage return/line feed. So now, I have one file with one record.

Basically,I need to know how to remove the carriage returns/line feeds
in the file EXCEPT for the ones that is END OF LINE. Can somebody help
me please?

Dim strSearchString, objFSO, objFile
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\Test\Project.csv", ForReading)
strSearchString = objFile.ReadAll
objFile.Close

objFSO.CreateTextFile "d:\Test\Project_" & DatePart("yyyy",Date) &
Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d", Date),2)
& ".csv"
Set objFile = objFSO.OpenTextFile("d:\Test\Project_" & DatePart
("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" &
DatePart("d", Date),2) & ".csv", ForWriting)
strSearchString = Replace(strSearchString, VbCrLf, "")
strSearchString = Replace(strSearchString, Vbtab, "")

objFile.Write strSearchString
objFile.Close

When I read a text file I use the ReadLine method of the file object. I
loop
through all lines of the file until the AtEndOfStream condition is met. I
also check each line to see if it is blank:
======
Do Until objFile.AtEndOfStream
strLine = Trim(objFile.ReadLine)
If (strLine <> "") Then
' Process the line...
End If
Loop
=====
Alternatively, I use the ReadAll method and use the Split function to
convert into an array of lines. Again, any line can be blank, especially
the
last line:
===
arrLines = Split(objFile.ReadLine, vbCrLf)
For Each strLine In arrLines
If (strLine <> "") Then
' Process the line...
End If
Next

--
Richard Mueller
MVP Directory Services
Hilltop Lab -http://www.rlmueller.net
--- Hide quoted text -

- Show quoted text -

Here is what I have and I still see the carriage returns and line feed

Dim strLine, objFSO, objInput, objOutput
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile("d:\Test\Project.csv", ForReading)

objFSO.CreateTextFile "d:\Test\Project_" & DatePart("yyyy",Date) &
Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d", Date),2)
& ".csv"
Set objOutput = objFSO.OpenTextFile("d:\Test\Project_" & DatePart
("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" &
DatePart("d", Date),2) & ".csv", ForWriting)

Do Until objInput.AtEndofStream
strLine = Trim(objInput.ReadLine)
If (strLine <> "") Then
strLine = Replace(strLine, vbCrLf, "")
strLine = Replace(strLine, vbtab,"")
objOutput.WriteLine strLine

End If
Loop

objInput.Close
objOutput.Close
-------------
Pegasus's suggestion may be best. The only thing I can think of is that your
comma delimited file has carriage returns embedded in the field values. If
the Replace function doesn't remove them, maybe they are vbCr or vbLf
characters in addition to vbCrLf. I would try:
=======
Do Until objInput.AtEndofStream
    strLine = Trim(objInput.ReadLine)
    If (strLine <> "") Then
        strLine = Replace(strLine, vbCrLf, "")
        strLine = Replaced(strLine, vbCr, "")
        strLine = Replaced(strLine, vbLf, "")
        strLine = Replaced(strLine, vbFormFeed, "")
        strLine = Replace(strLine, vbtab,"")
        objOutput.WriteLine strLine
    End If
Loop
========
vbCrLf     is Chr(13) & Chr(10) (ANSI carriage return and line feed)
vbCr       is Chr(13) (ANSI carriage return)
vbLf       is Chr(10) (ANSI line feed)
vbFormFeed is Chr(12) (ANSI form feed)

--
Richard Mueller
MVP Directory Services
Hilltop Lab -http://www.rlmueller.net
--- Hide quoted text -

- Show quoted text -

What Richard is saying is correct.....the carriage returns and line
feeds is embedded in the field values. Richard: I tried your code..it
removed the tab,but did not remove the carriage return nor the line
feed.
.



Relevant Pages

  • Re: End of Line
    ... new line feeds through the file, it ALSO removes the END OF LINE ... carriage return/line feed. ... For Each strLine In arrLines ...
    (microsoft.public.scripting.vbscript)
  • Re: End of Line
    ... new line feeds through the file, it ALSO removes the END OF LINE ... carriage return/line feed. ... For Each strLine In arrLines ...
    (microsoft.public.scripting.vbscript)
  • Re: End of Line
    ... new line feeds through the file, it ALSO removes the END OF LINE ... carriage return/line feed. ... For Each strLine In arrLines ... Type these commands at the Command Prompt: ...
    (microsoft.public.scripting.vbscript)
  • Re: End of Line
    ... new line feeds through the file, it ALSO removes the END OF LINE ... carriage return/line feed. ... strSearchString = Replace(strSearchString, VbCrLf, "") ... For Each strLine In arrLines ...
    (microsoft.public.scripting.vbscript)
  • Re: End of Line
    ... new line feeds through the file, it ALSO removes the END OF LINE ... carriage return/line feed. ...    Dim sSQL ... original script seemed to have work, however, it all also removed CRLF ...
    (microsoft.public.scripting.vbscript)