Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to strip out carriage returns from a text file

Status
Not open for further replies.

jewilson2

Technical User
Feb 7, 2002
71
US
I have a process written in access that imports a text file, runs a make table query against the imported table (to do some reformatting, record selection, etc) then exports the made table to a fixed length text file. This works like a champ, and I will automate it with a VB module. The problem is, it exports the file with a carriage return line feed after every record (as expected). Is there a way to either export the file without CRLF or open the exported file and strip the CRLF out then write to another text file?

Thanks,
JW
 
You do realize that if it doesn't contain these characters your data is going to be one humongous string in your file, don't you?

 
Yes.

The program that then needs to read this file wants it sequential...no CRLF.

thanks
 
Ok, I'm much closer.

The following code successfully strips out all CrLf from the end of each record but leaves one at the end of the file which still blows up the program reading this file. Is there a way to strip the CrLf from each record AND from the EOF?

Open "\\lfh_homer\department\check_data\ap\checkrecout.txt" For Input As #1

filen = LOF(1)
InputData = Input(filen, #1)
rstring2 = Replace(InputData, vbCrLf, "")
Close #1 'Close File.
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile ("\\lfh_homer\department\check_data\ap\CB185-TAPE")
Set f = fs.GetFile("\\lfh_homer\department\check_data\ap\CB185-TAPE")
Set ts = f.OpenAsTextStream(2, -2)
ts.WriteLine (rstring2)
ts.Close
 
instead of
ts.WriteLine (rstring2)
try
ts.Write (rstring2)


Will write the data without putting a line feed in.

hth

Ben


----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top