Description |
If the current string has not been exhausted, the block of characters are returned.
The string position is updated accordingly.
Carriage return and Line-feed characters are not returned by this method.
An attempt is made to read up to Count characters. These characters are overlaid onto the Characters array from StartIndex. The returned integer value is the number of characters overlaid. Zero if the string was already exhausted before the read.
|
| Notes | You must set the length of the target Character array, and it must have sufficient capacity to hold the returned characters.
|
|
Microsoft MSDN Links |
System.IO
System.IO.StringReader
|
|
|
Reading blocks of characters |
program Project1;
{$APPTYPE CONSOLE}
uses
System.IO;
var
Reader : System.IO.StringReader;
MultiLineString : String;
CharArray : Array of Char;
CharCount : Integer;
begin
// Define our multi line string
MultiLineString := 'Hello cruel World';
// Create our String Reader
Reader := System.IO.StringReader.Create(MultiLineString);
// Create our target character array
SetLength(CharArray, 4);
// Read the characters from the string in blocks
CharCount := Reader.ReadBlock(CharArray, 0, 4);
while CharCount > 0 do
begin
Console.WriteLine(CharCount.ToString +
' chars read : ' +
CharArray);
// Clear the char array before assigning into it
CharArray[0] := ' ';
CharArray[1] := ' ';
CharArray[2] := ' ';
CharArray[3] := ' ';
CharCount := Reader.ReadBlock(CharArray, 0, 4);
end;
Console.Readline;
end.
| Show full unit code | 4 chars read : Hell
4 chars read : o cr
4 chars read : uel
4 chars read : Worl
1 chars read : d
|
|
|
|