From Clomosy Docs

No edit summary
No edit summary
Line 1: Line 1:
function Copy(Source string; StartChar, Count Integer):string;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function Copy(S: String; Index: Integer; Count: Integer): string;
</div>


The copy function provides copying of a value. Creates a new array from part of an existing array.<br>
Returns a substring of a string or a segment of a dynamic array.<br>
String copy:<br>
The index of the first character of a string is = 1. Count characters are copied from the StartChar of the Source string to the returned string. Less than Count characters if the end of the Source string is encountered before the Count characters are copied.<br>


'''Example:'''<br>
:<b>S:</b> An expression of a string or dynamic-array type.
:'''Base Syntax'''
:<b>Index and Count:</b> Integer-type expressions.
  var
Copy returns a substring or subarray containing Count characters or elements starting at S[Index]. The substring or subarray is a unique copy (that is, it does not share memory with S; if the elements of the array are pointers or objects, these are not copied). If Index is larger than the length of S, Copy returns an empty string or array.<br>
    Source, Target : string;
If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned.<br>
 
  begin
    Source := '12345678';
    Target := Copy(Source, 3, 4);
    ShowMessage('Target : '+Target);
  end;


:'''TRObject Syntax'''
<div class="alert alert-warning" role="alert" data-bs-theme="light">
<b>Notes:</b> Copy uses one-based array indexing even on platforms where strings are zero-based. When S is a dynamic array, you can omit the Index and Count parameters, and Copy copies the entire array.
</div>


  var
<b>Example</b><br>
    Source, Target : string;
<b>TRObject Syntax</b><br>
 
<pre>
   {
var
    Source = '12345678';
   Source, Target : string;
    Target = Copy(Source, 3, 4);
    ShowMessage('Target : '+Target);
  }


'''Output:'''<br>
{
Target : 3456
  Source = '12345678';
  Target = Copy(Source, 3, 4);
  ShowMessage('Target : '+Target);
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  Source, Target : string;
 
begin
  Source := '12345678';
  Target := Copy(Source, 3, 4);
  ShowMessage('Target : '+Target);
end;
</pre>
 
<b>Output:</b><br>
<div class="alert alert-success" role="alert" data-bs-theme="light">
Target : 3456
</div>

Revision as of 06:43, 7 October 2024

Returns a substring of a string or a segment of a dynamic array.

S: An expression of a string or dynamic-array type.
Index and Count: Integer-type expressions.

Copy returns a substring or subarray containing Count characters or elements starting at S[Index]. The substring or subarray is a unique copy (that is, it does not share memory with S; if the elements of the array are pointers or objects, these are not copied). If Index is larger than the length of S, Copy returns an empty string or array.
If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned.

Example
TRObject Syntax

var
  Source, Target : string;

{
  Source = '12345678';
  Target = Copy(Source, 3, 4);
  ShowMessage('Target : '+Target);
}

Base Syntax

var
  Source, Target : string;

begin
  Source := '12345678';
  Target := Copy(Source, 3, 4);
  ShowMessage('Target : '+Target);
end;

Output: