Hi,
Is there a function to read a specific line of text from a .txt file?
Something like: cText := ReadText( cFile, nLine )
function ReadText( cFile, nLine )
local cBuf := MemoRead( cFile )
local nAt
if ( nAt := NumAt( CRLF, cBuf, nLine ) ) == 0
cBuf := ''
else
cBuf := SubStr( cBuf, nAt + 2 )
if ( nAt := At( CRLF, cBuf ) ) > 0
cBuf := Left( cBuf, nAt - 1 )
endif
endif
return cBuf
local aEol := { Chr(13) + Chr(10), Chr(10) }, ;
SLINE := SPACE(20), ;
hFile
hFile := FOPEN(xxxxx)
WHILE HB_FReadLine( hFile, @sLine, aEol ) == 0
// retreive sline here
END
fclose(hFile)
Jeff Barnes wrote:Just an addition to my original post ....
I am looking for something where I do not have to load the entire file into memory if possible.
function ReadText( cFile, nLine )
local hFile := HB_FUse( cFile )
local cLine := ""
HB_FGoto( nLine )
if .not. HB_FEof()
cLine := HB_FReadLN()
endif
HB_FUse()
return cLine
cString := MemoRead( "File.ext" )
nLines := MLCount( cString, 400) // Line Count
? MemoLine( cString,400, 2 ) // return line 2 of cstring
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 89 guests