Re: End of Line

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



On Sep 8, 2:36 pm, Odd <audrey....@xxxxxxxxx> wrote:
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.- Hide quoted text -

- Show quoted text -

-d 100 500

13D9:0100 50 72 6F 6A 65 63 74 5F-49 44 2C 50 72 6F 6A 65
Project_ID,Proje
13D9:0110 63 74 5F 4E 61 6D 65 2C-48 69 67 68 5F 4C 65 76
ct_Name,High_Lev
13D9:0120 65 6C 5F 4F 75 74 6C 69-6E 65 2C 45 61 72 6C 79
el_Outline,Early
13D9:0130 5F 49 64 65 6E 74 69 66-69 65 64 5F 52 69 73 6B
_Identified_Risk
13D9:0140 73 2C 50 72 6F 6A 65 63-74 5F 43 75 72 72 65 6E
s,Project_Curren
13D9:0150 63 79 5F 49 44 0D 0A 35-2C 50 72 6F 6A 65 63 74 cy_ID..
5,Project
13D9:0160 20 41 2C 54 42 44 20 20-20 20 20 20 20 20 20 20
A,TBD
13D9:0170 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0180 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0190 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:01A0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:01B0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:01C0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:01D0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:01E0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:01F0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0200 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0210 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0220 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0230 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0240 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0250 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0260 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0270 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0280 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0290 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:02A0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:02B0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:02C0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:02D0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:02E0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:02F0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0300 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0310 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0320 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0330 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0340 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0350 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0360 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0370 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0380 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0390 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:03A0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:03B0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:03C0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:03D0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:03E0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:03F0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0400 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0410 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0420 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0430 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0440 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0450 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0460 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0470 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0480 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0490 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:04A0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:04B0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:04C0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:04D0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:04E0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:04F0 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20
20
13D9:0500 20
-q

.



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)