Home  |  Delphi .net Home  |  System.IO.StringReader  |  Peek Method
  
Peek  
Method  
Gives the value of the next character in the string without updating position
StringReader Class
System.IO NameSpace
CF1.  Function Peek : Integer;
CF : Methods with this mark are Compact Framework Compatible
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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.
   Hello[CR][LF]c
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author