Click or drag to resize

FGetS Function (IntPtr)

X#
Read a line from an open file.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION FGetS(
	ptrHandle AS IntPtr
) AS STRING
Request Example View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the file to read from.

Return Value

Type: String
The line read. When the end-of-file is reached, FGets() returns a NULL_STRING and FError() is set to 257.
Remarks
This function is the same as FReadLine(). Both functions are assumed to handle raw binary data and are not dependent upon the status of SetAnsi(). FReadText() and FRead4(), on the other hand, are dependent upon SetAnsi().
Examples
This example uses FGets() to read an entire file without specifying a value for nMax:
X#
1ptrHandle := FOpen2("docs.txt", FO_READ)
2IF ptrHandle != F_ERROR
3    DO WHILE !FEOF(ptrHandle)
4        ? FGets(ptrHandle)
5    ENDDO
6ENDIF
7FClose(ptrHandle)
The following example provides a utility that displays and counts all occurrences of a string within a file:
X#
 1FUNCTION Grep(cSearch, cFile AS STRING) ;
 2        AS DWORD PASCAL
 3    LOCAL handle AS PTR
 4    LOCAL Count AS DWORD
 5    LOCAL Line AS STRING
 6    handle := FOpen2(cFile, FO_READ)
 7    cSearch := Upper(cSearch)
 8    DO WHILE !FEOF(handle)
 9        line := Upper(FGets(handle))
10        IF InStr(cSearch, line)
11            ? line
12            Count += 1
13        ENDIF
14    ENDDO
15    RETURN Count
See Also