{"title":"Text.CopyStr(Text, Integer [, Integer]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/text/text-copystr-method/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/text/text-copystr-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Copies a substring of any length from a specific position in a string (text or code) to a new string.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Text.CopyStr(Text, Integer [, Integer]) Method","slug":"textcopystrtext-integer-integer-method","at":0,"chars":2166},{"level":2,"title":"Syntax","slug":"syntax","at":211,"chars":176},{"level":2,"title":"Parameters","slug":"parameters","at":387,"chars":817},{"level":2,"title":"Return Value","slug":"return-value","at":1204,"chars":66},{"level":2,"title":"Remarks","slug":"remarks","at":1270,"chars":150},{"level":2,"title":"Example","slug":"example","at":1420,"chars":614},{"level":2,"title":"Related information","slug":"related-information","at":2034,"chars":132}],"text":"# Text.CopyStr(Text, Integer [, Integer]) Method\n> Version: _Available or changed with runtime version 1.0._\nCopies a substring of any length from a specific position in a string (text or code) to a new string.\n## Syntax\n```al\nNewString :=   Text.CopyStr(String: Text, Position: Integer [, Length: Integer])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nString\nType: text-data-type\nThe string that you want to copy from.\nPosition\nType: ../integer/integer-data-type\nThe 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.\n*[Optional] Length*\nType: ../integer/integer-data-type\nThe 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.\n## Return Value\nNewString\nType: text-data-type\nThe copied string.\n## Remarks\nIf Position combined with Length exceeds the length of the string, all the characters from Position to the end of the string are returned.\n## Example\n```al\nvar\n    Str: Text[30];\n    Position: Integer;\n    Length: Integer;\n    NewStr: Text[30];\n    Text000: Label 'Using the CopyStr method';\n    Text001: Label 'The original string is:>%1<';\n    Text002: Label 'The copied string is:>%1<';\nbegin\n    Str := Text000;\n    Position := 7;\n    Length := 8;\n    Message(Text001, Str);\n    NewStr := CopyStr(Str, Position, Length);\n    Message(Text002, NewStr);\nend;\n```\nThe first message window shows the original string:\nThe original string is:\n>Using the CopyStr method\\<\nThe second message window shows the copied string:\nThe copied string is:\n>the Copy\\<\n## Related information\ntext-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}