|
Reading Text Files |
Top Previous Next |
|
What is translated > File Input and Output > Reading Text Files Read and ReadLn read values from a TextFile.
Calls without an explicit file parameter read from the predefined Input file.
READ
Read reads a value without automatically moving to the next line.
char character = '\0'; int number = 0; string text = string.Empty;
Read(myFile, ref character); Read(myFile, ref number); Read(myFile, ref text);
Character input reads one character.
Numeric input skips leading white space and reads the next numeric value.
String input reads the remaining characters of the current line.
READLN
ReadLn reads a value and then consumes the rest of the current line, including the line ending.
ReadLn(myFile, ref text);
ReadLn without a value skips the remaining part of the current line:
ReadLn(myFile);
Calls without a file parameter use Input:
ReadLn(ref text);
EOF
Eof returns true when no more data can be read.
while (!Eof(myFile)) { ReadLn(myFile, ref text); }
For typed and untyped files, Eof compares the current stream position with the file length.
The parameterless Eof function uses Input:
while (!Eof()) { ReadLn(ref text); }
EOLN
Eoln is available for text files.
It returns true when the next character is a line ending or when the end of the file has been reached.
if (Eoln(myFile)) ReadLn(myFile);
The parameterless Eoln function uses Input. |
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |