Home  |  Delphi .net Home  |  System.String  |  SubString Method
SubString  
Method  
Returns a section of a string
String Class
System NameSpace
CF1.  Function SubString ( Start : Integer; ) : String ;
CF2.  Function SubString ( Start:IntegerStart : Integer; Count : Integer; ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns a new string containing the section of the current string statring at index position Start.
 
Optionally, the extracted section length can be limited to a maximum of Count characters.
Notes
Very Important : Methods in .Net treat strings as starting at 0, unlike traditional Delphi where they started at 1.

Like a lot of string methods, the string object itself is not affected - the modified string is returned for assignment.
Microsoft MSDN Links
System
System.String
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  strA, strB, strC : String;

begin
  strA := '0123456789';
  strB := strA.SubString(5);
  strC := strA.SubString(5, 2);

  Console.WriteLine('strA = ' + strA);
  Console.WriteLine('strB = ' + strB);
  Console.WriteLine('strC = ' + strC);

  Console.ReadLine;
end.
Show full unit code
  strA = 0123456789
  strB = 56789
  strC = 56
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author