FGetS Function (IntPtr, DWord) | |
Read a line from an open file.
Namespace:
XSharp.Core
Assembly:
XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax FUNCTION FGetS(
ptrHandle AS IntPtr,
nMax AS DWORD
) AS STRING
public static string FGetS(
IntPtr ptrHandle,
uint nMax
)
Request Example
View SourceParameters
- ptrHandle
- Type: IntPtr
The handle of the file to read from. - nMax
- Type: DWord
The maximum number of characters to read per line. FGets() will read until a hard carriage return (Chr(13)) is reached, end-of-file is encountered, or nMax characters are read.
The default value for nMax is 256.
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:
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:
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