Home  |  Delphi .net Home  |  System.String  |  ToCharArray Method
  
ToCharArray  
Method  
Creates a character array from a string
String Class
System NameSpace
CF1.  Function ToCharArray : Array of Char;
NotCF2.  Function ToCharArray ( Start : Integer; Count : Integer ) : Array of Char;
CF : Methods with this mark are Compact Framework Compatible
Description
Builds an array of characters from the current string.
 
Optionally, the Start index in the string, and the Count of characters can be specified.
Notes
Very Important : Methods in .Net treat strings as starting at 0, unlike traditional Delphi where they started at 1.
Microsoft MSDN Links
System
System.String
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  strA      : String;
  charArray : Array of Char;
  len       : Integer;

begin
  strA      := 'Hello';
  charArray := strA.ToCharArray;
  len       := Length(charArray);

  Console.WriteLine('strA             = ' + strA);
  Console.WriteLine('charArray        = ' + charArray);
  Console.WriteLine('charArray length = {0}', len.ToString);

  Console.ReadLine;
end.
   strA             = Hello
   charArray        = Hello
   charArray length = 5
Using only a section of the string
program Project1;
{$APPTYPE CONSOLE}

var
  strA      : String;
  charArray : Array of Char;
  len       : Integer;

begin
  strA      := '0123456789';
  charArray := strA.ToCharArray(6, 2);
  len       := Length(charArray);

  Console.WriteLine('strA             = ' + strA);
  Console.WriteLine('charArray        = ' + charArray);
  Console.WriteLine('charArray length = {0}', len.ToString);

  Console.ReadLine;
end.
   strA             = 0123456789
   charArray        = 67
   charArray length = 2
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author