Delphi Basics Home  |  Delphi Basics .NET Home  |  System.IO.StringReader  |  ReadLine Method
ReadLine  
Method  
Reads the next line of characters from the current string
StringReader Class
System.IO NameSpace
CF1.  Function ReadLine : String;
CF : Methods with this mark are Compact Framework Compatible
Description
If the current string has not been exhausted, the next sequence of characters are returned as a string as far as either a carriage return : Chr(13), line-feed : Chr(10) or both, or the end of the string are encountered. The carriage return and line feed characters are not returned in the string.
 
After returning the string, the read position in the string is moved to the character after the carriage return or line-feed or last character of the string, as appropriate.
 
A Nil string is returned if there are no more characters to return.
Microsoft MSDN Links
System.IO
System.IO.StringReader
System.IO.StringReader.ReadLine
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Reader           : System.IO.StringReader;
  MultiLineString  : String;
  SingleLineString : String;

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);

  // Read the lines from our multi line string
  repeat
    SingleLineString := Reader.ReadLine;
    Console.WriteLine(SingleLineString);
  until SingleLineString = Nil;

  Console.Readline;
end.
   Hello
   cruel
   World
 
© CodeGear 2006 - 2007. All rights reserved.