Text.CopyStr(Text, Integer [, Integer]) Method

Version: Available or changed with runtime version 1.0.

Copies a substring of any length from a specific position in a string (text or code) to a new string.

Syntax

NewString :=   Text.CopyStr(String: Text, Position: Integer [, Length: Integer])

Note

This method can be invoked without specifying the data type name.

Parameters

String
 Type: Text
The string that you want to copy from.

Position
 Type: Integer
The position of the first character to copy. If the value of Position is less than 1, then the COPYSTR function returns an error. If Position is greater than the length of the string, then the COPYSTR function returns an empty string.

[Optional] Length
 Type: Integer
The number of characters to copy. If the value of Length is less than 0, then the COPYSTR function returns an error. If the value of Length causes Position + Length to be > (total length of the string), then the result includes all the characters from Position to the end of the string. If you omit Length, then the resulting string includes all the characters from Position to the end of the string.

Return Value

NewString
 Type: Text
The copied string.

Remarks

If Position combined with Length exceeds the length of the string, all the characters from Position to the end of the string are returned.

Example

var
    Str: Text[30];
    Position: Integer;
    Length: Integer;
    NewStr: Text[30];
    Text000: Label 'Using the CopyStr method';
    Text001: Label 'The original string is:>%1<';
    Text002: Label 'The copied string is:>%1<';
begin
    Str := Text000;  
    Position := 7;  
    Length := 8;  
    Message(Text001, Str);  
    NewStr := CopyStr(Str, Position, Length);  
    Message(Text002, NewStr);  
end;

The first message window shows the original string:

The original string is:

>Using the CopyStr method<

The second message window shows the copied string:

The copied string is:

>the COPY<

Text Data Type
Get Started with AL
Developing Extensions