Description |
The integer value of the next character in the current string is returned, but the position is not moved to the next character. The character is literally 'peeked'.
If the string has already been exhausted, -1 is returned.
|
|
Microsoft MSDN Links |
System.IO
System.IO.StringReader
|
|
|
Stopping string read before a certain character is read |
program Project1;
{$APPTYPE CONSOLE}
uses
System.IO;
var
Reader : System.IO.StringReader;
MultiLineString : String;
CharAsInteger : Integer;
begin
// Define our multi line string
MultiLineString := 'Hello' + Chr(13) + Chr(10) +
'cruel' + Chr(13) + Chr(10) +
'World';
// Create our String Reader
Reader := System.IO.StringReader.Create(MultiLineString);
// Keep reading but stop before the first 'r'
while Reader.Peek <> Ord('r') do
begin
CharAsInteger := Reader.Read;
if CharAsInteger = 13 // Carriage Return
then Console.Write('[CR]')
else if CharAsInteger = 10 // Line-feed
then Console.Write('[LF]')
else Console.Write(Char(CharAsInteger));
end;
Console.Readline;
end.
| Show full unit code | Hello[CR][LF]c
|
|
|
|