# 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
```al
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-data-type
The string that you want to copy from.
Position
Type: ../integer/integer-data-type
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/integer-data-type
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-data-type
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
```al
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\<
## Related information
text-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/text/text-copystr-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/text/text-copystr-method/
