FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour What is the best way read a txt file?
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM
What is the best way read a txt file?
Posted: Sat Jan 12, 2008 02:46 AM

hi,
I know xharbour has functions:

hfile:=hb_Fuse("ccc.txt")
while !hb_feof()
c1:=hb_freadln()
hb_fskip(1)
end
hb_fuse()
fclose(hfile)
but harbour without.

Are there lists of what functions each harbour libs files includes ?

Regards!
Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
What is the best way read a txt file?
Posted: Sat Jan 12, 2008 05:53 AM

How about just:

cText := memoread( "myfile.txt")

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 167
Joined: Thu Mar 22, 2007 11:24 AM
What is the best way read a txt file?
Posted: Sat Jan 12, 2008 09:56 AM

James,

I think memoread has a limitation (or at least memoline) : linelength must be less as 254

Frank

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
What is the best way read a txt file?
Posted: Sat Jan 12, 2008 12:05 PM

Frank,

MemoRead() is fine but MemoLine() should not be used as it is very slow.

Please review fwh\samples\RE.prg to see how to read lines from text, real fast :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
What is the best way read a txt file?
Posted: Sat Jan 12, 2008 12:42 PM
Antonio Linares wrote:Frank,

MemoRead() is fine but MemoLine() should not be used as it is very slow.

Please review fwh\samples\RE.prg to see how to read lines from text, real fast :-)


xHarbour offers HB_FReadLine() that should be fast enough.

EMG
Posts: 56
Joined: Mon Jul 03, 2006 02:34 AM
What is the best way read a txt file?
Posted: Sun Jan 13, 2008 04:13 AM

Antonio,
RE.prg uses TTxtFile which, although I haven't used it, seems to assume each line is already terminated by CRLF. Wouldn't your suggestion only apply if the text file had no "soft" lines (which a normal paragraph would have)?

Col

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
What is the best way read a txt file?
Posted: Sun Jan 13, 2008 04:21 AM
Colin,

> RE.prg uses TTxtFile

Thats an old version of samples\RE.prg. The current RE.prg sample does not use TTxtFile and does it in a total different way:
      cTxtFile = MemoRead( cRCFile )
      nFrom = 1

      while nFrom < Len( cTxtFile )
         cLine = ExtractLine( cTxtFile, @nFrom )
         ...
         SysRefresh()
      end

ExtractLine() is a new FWH function
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
What is the best way read a txt file?
Posted: Sun Jan 13, 2008 04:32 AM
If we know we are dealing with a text file containing fixed width lines
for nFrom := 1 to nSize step nLineWidth
   cline := substr( ctext, nfrom, nlinewidth )
next

to extract a particular line number :
cline := substr( ctext, ( nlinenumber- 1 ) * nlinewidth + 1, nlinewidth )


Extractline from FWH and the above code are enough to deal with text files containing variable length lines or fixed width lines.

If we like OOPS we can put the same code in a class.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion