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

Reading from a text file 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am reading from a text file, substituting some words and then creating a new file. The code below works but the FILETOSTR function is not wrapping lines just at line feeds but on other chars too.
Is there a way to make it wrap on line feeds or indeed, a better way to read a text file line by line?

Code:
C=FCREATE(FILENAME,0)
M.LCTEXT = FILETOSTR('d:/studioftp/pagetemps/member.pag')
FOR I = 1 TO MEMLINES(m.LCTEXT)
	L = MLINE(m.LCTEXT,I)
	L=STRTRAN(L,'XXXNAME',ALLTRIM(PAGEINFO[2]))
	L=L+CHR(13)+CHR(10)
	W=FWRITE(C,L)
ENDFOR
CL=FCLOSE(C)

Keith
 
FILETOSTR is just reading File in 1:1

What is wrapping text at unwanted positions is MLINES, as it's result depends on SET MEMOWIDTH. Read about MLINE():

The length and number of the lines in a memo field are determined by the current value of SET MEMOWIDTH (the default line length is 50 characters). If a carriage return is encountered, no additional characters are returned. The current _WRAP setting determines how the memo field line is displayed

Why do peopole still use such things in the age of proprtional fonts anyway?
Why split into lines at all? You simply could do one STRTRAN oon the full text and line breaks are kept where they are.

STRTOFILE(STRTRAN(FILETOSTR('d:/studioftp/pagetemps/member.pag'),'XXXNAME',ALLTRIM(PAGEINFO[2])))

Bye, Olaf.


 
One Correction - STRTOFILE() also needs the destination file name, so it's:

STRTOFILE(STRTRAN(FILETOSTR('d:/studioftp/pagetemps/member.pag'),'XXXNAME',ALLTRIM(PAGEINFO[2])),FILENAME)

Bye, Olaf.
 
Thanks Olaf
I assumed that I had to deal with one line at a time but it works by reading the whole file into a string. I thought that the 255 char limit would apply here but it seems to be fine up to now.

Keith
 
That limit does only apply to string you write in code in string delimiters as " or ' or []. It already does not apply to TEXT..ENDTEXT and your code also initially read in the whole file into M.LCTEXT.

The limit for string variables is 16MB, there's a help chapter about that. Actually it's a theoretical limit, you can simply check whether you can read in longer files. Anyway, your own code would fail on the same limit for FILETOSTR and everything afterwards only would split things into smaller portions. But once the text is in memory without any error, further processing is no problem, is it? Only , if there would be a shorter limit for STRTRAN(), but I don't see that.

Bye, Olaf.
 
I have found new interest in FoxPro and I am keen to fill in the many gaps in my knowledge, I am grateful for the all the help you are kindly offering. Google is a good friend here but in the end, someone who can actually do the job is worth their weight in gold.
Thanks

Keith
 
The key takeaway here is that the limit is on storing text to a memory variable. So take the memory variable out of the mix!

You can also do that with APPEND MEMO to get to a string in a memo field that you can manipulate, but since we got FileToStr() and StrToFile() that technique took a distant back seat.
 
You can also do that with APPEND MEMO to get to a string in a memo field that you can manipulate, but since we got FileToStr()

Another way to get around the memory variable char count limitation is to use an Array

Code:
DIMENSION aryFileStr(1)
aryFileStr(1) = FILETOSTR(InputTextFile)

Then the array can be used for most situations in lieu of a memory variable.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top