Home  |  Delphi .net Home  |  System.IO.StringReader  |  ReadBlock Method
Reads the next block of characters from the current string
StringReader Class
System.IO NameSpace
CF1.  Function ReadBlock ( Characters : Array of Char; StartIndex : Integer; Count : Integer ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
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.
You must set the length of the target Character array, and it must have sufficient capacity to hold the returned characters.
Microsoft MSDN Links
 Author links

 Buy Website Traffic at

 Buy Proxies at
Reading blocks of characters
program Project1;


  Reader           : System.IO.StringReader;
  MultiLineString  : String;
  CharArray        : Array of Char;
  CharCount        : Integer;

  // 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
    Console.WriteLine(CharCount.ToString +
                      ' chars read : '   +

    // Clear the char array before assigning into it
    CharArray[0] := ' ';
    CharArray[1] := ' ';
    CharArray[2] := ' ';
    CharArray[3] := ' ';
    CharCount := Reader.ReadBlock(CharArray, 0, 4);

   4 chars read : Hell
   4 chars read : o cr
   4 chars read : uel
   4 chars read : Worl
   1 chars read : d
Delphi Programming Neil Moffatt All rights reserved.  |  Contact the author