xHarbour Reference Documentation > Function Reference |
Counts the lines in an ASCII text file.
FLineCount( <cFileName> ) --> nLineCount
The function returns the number of lines contained in <cFileName> as a numeric value. If the file <cFileName> does not exist or cannot be opened, the return value is zero.
FLineCount() is an optimized function for counting the lines in an ASCII text file fast and efficiently. It can be used in conjunction with HB_FReadLine() to extract single lines from an ASCII text file.
See also: | FileStats(), FCharCount(), FCreate(), FOpen(), FParse(), FWordCount(), HB_FReadLine(), MemoLine(), MlCount() |
Category: | File functions , xHarbour extensions |
Source: | rtl\fparse.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example uses FLineCount() to determine the size of an // array used to collect all lines of a text file. PROCEDURE Main LOCAL cFileName := "Test.txt" LOCAL nCount := FLineCount( cFileName ) LOCAL aLines := Array( nCount ) LOCAL nFileHandle := FOpen( cFileName ) LOCAL nLine := 0 LOCAL cLine FOR EACH cLine IN aLines HB_FReadLine( nFileHandle, @cLine ) aLines[ ++nLine ] := cLine END FClose( nFileHandle ) ? Len( aLines ) AEval( aLines, {|c| QOut( c ) } ) RETURN
http://www.xHarbour.com