xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_FReadLine()

Extracts the next line from a text file.

Syntax

HB_FReadLine( <nFileHandle> , ;
              @<cLine>      , ;
             [<caEndOfLine>], ;
             [<nLineLength>]  ) --> nReturn

Arguments

<nFileHandle>
This is a numeric file handle returned from function FOpen().
@<cLine>
A memory variable that must be passed by reference to HB_FReadLine(). It receives the character string read from the text file. <cLine> does not need to be initialized.
<caEndOfLine>
The parameter is optional. It is either a character string containing the end-of-line characters, or an array of character strings, each element of which contains end-of-line characters. The default value for <caEndOfLine> is Chr(13)+Chr(10) (Carriage return, Line feed).
<nLineLength>
This is an optional numeric value specifying the maximum line length the function searches for the next <caEndOfLine>. The default value is 4096.

Return

The function returns 0 when the next text line is read from the file. A value not equal zero is returned when no more lines are available to read.

Description

HB_FReadLine() is an efficient extraction routine for getting the next available line from an ASCII text file. It differs from FReadStr() in allowing a programmer to define the end-of-line character(s) HB_FReadLine() should recognize. Also, the maximum length of a line to search for the next end-of-line character(s) can be specified. The default value of 4096 is sufficient for most common text files.

Info

See also:FOpen(), FClose(), FCreate(), FReadStr(), MemoLine(), MemoRead()
Category: Low level file functions , xHarbour extensions
Source:rtl\fnsplit.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates an efficient way of loading single lines
// from an ASCII file into an array.

   PROCEDURE Main
      LOCAL cFileName   := "HB_FReadLine.prg"
      LOCAL aLines      := {}
      LOCAL nFileHandle := FOpen( cFileName )
      LOCAL cLine

      DO WHILE HB_FReadLine( nFileHandle, @cLine ) == 0
         AAdd( aLines, cLine )
      ENDDO
      // Add the last line
      AAdd( aLines, cLine )

      FClose( nFileHandle )

      ? Len( aLines )
      AEval( aLines, {|c| QOut( c ) } )
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe