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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to remove line feed characters 1

Status
Not open for further replies.

1421

Technical User
Feb 24, 2004
69
Hi Everyone, again.

This is about the txt file again. When creating the dbf, which I subsequently use to create the txt file, I am appending blank to create an empty record and replacing it with chr(12) (0C in hex). But my resulting txt file is giving me: 0C 0D 0A (chr(12)+chr(13)+chr(10) 13 plus 10 i believe is a line feed) at the end of the file. Is there a way i can remove the OD 0A from within Foxpro or prevent Foxpro from adding it on. i am using VFP Ver 9.

Thank You
 
have you tried to do...STRTRAN(CHR(12)+CHR(13)+CHR(10), CHR(12), fileName)
 
you mean:
STRTRAN(fieldname,CHR(12)+CHR(13)+CHR(10), CHR(12))
i just tried it on the data of that last record and it did NOT work. I tried your version with the filename & got only error messages, unless you mean something else (i tried using my dbf and the txt file, both returned in error).
 
Can you post several Lines of code that you use to
1. Create the table?
2. Field type you are replacing with CHR(12) (Memo I assume).
3. Code to output the dbf to txt file.


David W. Grewe Dave
 
Sure....
-----------------------------------------
Structure for table: G:\ELECTRONIC_BILLING\TEST1.
DBF
Number of data records: 0
Date of last update: 06/29/2007
Code Page: 1252
Field Field Name Type Width Dec Index Collate Nulls Next Step
1 DLINE Character 81 No
** Total ** 82
-----------------------------------------------------------
USE test1
APPEND FROM wbmd5900 DELIMITED WITH tab && wbmd5900.txt
..........
GOTO bott
APPEND BLANK
APPEND blank
REPLACE dline WITH CHR(12)
close data
*
sele 1
use test1
lnHandle=fcreate([test2.txt])
if lnHandle > 0
SELECT 1
DO WHILE NOT EOF()
mdline=RTRIM(dline)
fPUT(lnHandle,mdline)
SKIP
enddo
FCLOSE(lnHandle)
ENDIF
return
 
Add the code in red where indicated

Mdline=RTRIM(DLINE)

L_LEN=LEN(MdLine)
FOR x=1 TO L_LEN
L_check=ASC(SUBSTR(MdLine,x,1))
IF L_check < 32 OR L_check > 125
MdLine=STRTRAN(MdLine,CHR(L_check)," ")
ENDIF
ENDFOR
MdLine=ALLTRIM(STRTRAN(MdLine , " " , ' '))

fPUT(lnHandle,mdline)


David W. Grewe Dave
 
ok, i tried this and it's a little better, but still not it.
what i am getting now is ONLY the 0D 0A, instead of getting
0C 0D 0A. It is still throwing off my compare, as the production text file (created in Paradox DOS) only has 0C!
 
OD = Enter / Carrage Return / ASC(13)
OA = Line Feed / ASC(10)

You can try adding these lines

MDLINE=STRTRAN(MDLINE,CHR(10),'')
MDLINE=STRTRAN(MDLINE,CHR(13),'')
or
MDLINE=STRTRAN(MDLINE,'%OD','')
MDLINE=STRTRAN(MDLINE,'%OA','')

But I do not think it will help



David W. Grewe Dave
 
i did not help. I included all 4 lines and i am doing:
fPUT(lnHandle,mdline,1), adding that last 1 & it still not working!
 
fputs() writes CRLF after each string, so use FWRITE instead and add chr(13) only to every line you output:

replace
fput(lnHandle,mdline)
with
fwrite(lnHandle,mdline+chr(13))

Bye, Olaf.
 
Olaf,

Your idea worked!, as quoted in the Foxpro help:
Unlike FPUTS( ), FWRITE( ) doesn't place a carriage return and a line feed at the end of the character string.
By using the fwrite command I was a ble to write that record without the carrige return & now I am matching up excatly!

Thank you so much!

 
Which version of VFP are you using? Does it have STRTOFILE() and FILETOSTR()? They are the equivalent to the low level file reading and writing.
 
Then you can use FILETOSTR() and STRTOFILE(), if not now then the next time you need this functionality. STRTOFILE() has options for overwriting, not overwriting, or appending to the existing file.

Actually there was one program I maintained that was forced to use it. I was using FOPEN(), FREAD(), FWRITE and FCLOSE() to copy a file hidden from directory services and they failed when copying files larger than 12 MBs. Sometimes XP, always WinMe. I never did figure out why. (It would read and copied 12,090,000 bytes read before it reported error 43, "There is not enough memory to complete this operation.") But the new functions above were so much simpler to code and worked flawlessly in XP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top