What is the best way read a txt file?

What is the best way read a txt file?

Postby ShumingWang » Sat Jan 12, 2008 2: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
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Postby James Bott » Sat Jan 12, 2008 5:53 am

How about just:

cText := memoread( "myfile.txt")

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby demont frank » Sat Jan 12, 2008 9:56 am

James,

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

Frank
demont frank
 
Posts: 167
Joined: Thu Mar 22, 2007 11:24 am

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » 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
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Colin Wisbey » Sun Jan 13, 2008 4: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
Colin Wisbey
 
Posts: 56
Joined: Mon Jul 03, 2006 2:34 am

Postby Antonio Linares » Sun Jan 13, 2008 4: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:
Code: Select all  Expand view  RUN
      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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby nageswaragunupudi » Sun Jan 13, 2008 4:32 am

If we know we are dealing with a text file containing fixed width lines
Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10648
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 40 guests