Remove last CRLF in text file

S

stephan.anstoetz

Hi there,

I want to write a string from VBA into a text file. This file is an
input file for an Unix application, i.e. LF as the last character in a
file.
The Print statement does put me a CRLF at the end of every line. I got
around this problem to first concatenate the whole string with the
chr(13) LF and at the end write it into file.
This leaves me one CRLF at the very end of the file.

How do I get rid of this?
I tried to shorten the string by one character but than the string is
too short.
I re-read and re-wrote the file omitting the last line. No way. No
idea.

Any help is appreciated.
S.
 
V

Vergel Adriano

Perhaps use the Replace function to remove the CR character.

Replace(textwithCRLF, chr(10), "")
 
T

Tom Ogilvy

I believe he is saying the Print is putting the CRLF, so you can't use
replace on the newly written file and doing it before writing the file
wouldn't address the problem.


The OP could also try

Print #1, strng;

instead of
Print #1, strng

or if he needs a LF on the end

Print #1, strn & vbLf;
 
S

stephan.anstoetz

Replacing did not work.

But the semikolon did the trick.
Print #1, strng;
It omitted the CRLF at the end.
So I concatenated the string with a vbLn and then put a semikolon at
the end and I get what I want.
Print #1, strn & vbLf;

Many Thanks
S.
 

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