Home  |  Delphi .net Home  |  system.String  |  CopyTo Method
CopyTo  
Method  
Copies part of a string into a section of a Char array
String Class
system NameSpace
CF1.  Procedure CopyTo ( SourceStart:IntegerSourceStart : Integer; Target : Array of Char; TargetStart : Integer; Count : Integer; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Copies Count characters from the string object, starting at SourceStart to Target array of characters, from position TargetStart.
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
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  source : String;
  target : Array[1..12] of char;
  i      : Integer;

begin
  source := '012345678';

  for i := 1 to 12 do
    target[i] := '-';

  Console.WriteLine('Before CopyTo');
  Console.WriteLine('source = ' + source);
  Console.WriteLine('target = ' + target);

  source.CopyTo(3, target, 5, 4);

  Console.WriteLine('After CopyTo');
  Console.WriteLine('source = ' + source);
  Console.WriteLine('target = ' + target);

  Console.ReadLine;
end.
Show full unit code
  Before CopyTo
  source = 0123456789
  target = ------------
  After CopyTo
  source = 0123456789
  target = -----3456---
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author