Carriage Return

F

Francis Ang

I am using REPLACE command to remove carriage return and line feed from a
text file; but when I rename the text file from 'abc.txt' to 'abc.hex', the
carriage return mysteriously reappears.

I tried using the REPLACE command on 'abc.hex' file but it is not working.
REPLACE seems to work on text file only.

Any assistance will be greatly appreciated.

Thank you.
 
J

joel

I would like to see your code. Especially the way you are opening the file.
thre are some defaults on how the file is being opened. You ca open the file
as text or Unicode. You may be opening the file as unicode which really are
16 bit characters instead of 8 bit characters.I would also like to see your
replace statement.
 
F

Francis Ang

Hi Joel,

Thank you for responding so quickly. As requested, here is the code I wrote -

Sub CarriageRmv()
Open "C:\abc.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, cData

cDataNoCrLf = Replace(cData, vbCrLf, "")

Open "C:\NoCrLF.txt" For Append As #2
Print #2, cDataNoCrLf
Close #2

If EOF(1) Then
Close #1
Name "C:\NoCrLF.txt" As "C:\NoCrLf.hex"
Exit Sub
End If
Loop
End Sub
 
R

Rick Rothstein

Print statements put a CarriageReturn/LineFeed combination at the end of
each line it prints by default. You can suppress this default functionality
by placing a semi-colon at the end of the Print statement. Try it this
way...

Print #2, cDataNoCrLf;

Notice the semi-colon at the end of the statement.
 
J

Jacob Skaria

One more, you can also use...

Write #1, cDataNoCrLf

If this post helps click Yes
 
R

Rick Rothstein

I believe using Write on the OP's text file will encase the entire file in
quote marks. And, if the text contains quoted text within it, I believe
there will be some problems around those embedded text strings also. I
decided early on (maybe 25 years ago or so) to avoid using Write to put data
into a file because of what I considered at the time to be some odd
behaviors... in any event, I've found Print to do all I have ever needed
across the years, so I've always stuck with it when I need to write out to a
file.
 
F

Francis Ang

Thank you Jacob for your response and also Rick for sharing your experience.
 

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