removing line feeds from text files

G

Guest

I am trying to remove some line feed characters. I believe they are Chr(182)
(the paragraph sign)

My vba code sees the character but does not replace it with a blank, which
is what I need to do.

Public Sub GetText()


Dim intFile As Integer
Dim strInput As String
Dim outFile As Integer
Dim strCRLF As String
Dim strFill As String
Dim strClean As String

strCRLF = Chr(182)
strFill = " "


intFile = FreeFile()
Open "C:\Temp\MYREPORT.txt" For Input As #intFile
Open "C:\Temp\MY REPORT CLEAN.txt" For Output As #2
Do While Not EOF(intFile)

Line Input #intFile, strInput

strClean = Replace(strInput, strCRLF, strFill)

Debug.Print strClean
Write #2, strClean
Loop
Close #intFile
Close #2


End Sub
 
J

John Spencer

It is likely that the linefeeds in the file are either Chr(13) & Chr(10) or
just Chr(13).

Line input reads one line. It determines a line end by looking for one of
the above and then returns everything before Chr(13).
The Write # statement inserts commas between items and quotation marks
around strings as they are written to the file. You don't have to put
explicit delimiters in the list. Write # inserts a newline character, that
is, a carriage return-linefeed (Chr(13) + Chr(10)), after it has written the
final character in outputlist to the file.

So my guess is that you are removing the line feee when you read it and
putting it back when you write it to the file.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
J

John Spencer

One method would be to read every line and append them to a variable until
you read the entire file. Then write the variable out one time.

Do While Not EOF(intFile)
Line Input #intFile, strInput
strClean = StrClean & strInput
Loop
Write #2, strClean
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top