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

How to get rid of ascii character in my downloaded text file

Status
Not open for further replies.

samsiah

Programmer
Apr 5, 2001
2
MY
This is the example of text file as an output of my program.

2222222222222111 0123745121111005500
25550000099 0711111111111005500
2444444444444433 0000004411411005500
2111111111111222 0000006826557005500
2456000000000000A00000 3011555005500
3 (unwanted character)

There's an ascii character at the end of the text file which cause other program cannot read the file. Is there any way to get rid of this?
 
This is likely a DOS EOF character - ASCII 26 (0x1A, ^Z). If you are using VFP 6.0 the following would work.

=strtofile( strtran( filetostr( "file.txt" ), ;
chr(26), "" ) )

If you know it's the last character, you can use the low-level file routines to "lose" the last character.

*!* STRIPASCIIEOF.PRG
LPARAMETERS qcFileName

* Open the file with unbuffered read/write access
lnhandle = FOPEN(qcFileName,12)

* Test for possible file opening error
IF lnhandle = -1
WAIT WINDOW "Error Opening File: " ;
+ ALLTRIM(qcFileName)TIMEOUT 10
RETURN
ENDIF

l_nSize = FSEEK(lnHandle,0,2) && Determine file size
= FSEEK(lnHandle, -1, 2) && Need to sneak a peak at the last character
l_nLastChar = INT(ASC(FREAD(lnHandle,1)))

IF l_nLastChar = 0x1A && ASCII eof [or CHR(26)]
WAIT WINDOW "Stripping EOF" TIMEOUT 5 NOWAIT
l_nSize = l_nSize - 1
= FCHSIZE(lnHandle, l_nSize)
ENDIF

= FCLOSE(lnHandle)

RETURN
 
Thanks so much for you help rgbean! I'll try it first ok..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top