{"title":"Text.PadStr(Text, Integer [, Text]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/text/text-padstr-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-padstr-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-padstr-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":"Changes the length of a string to a specified length.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Text.PadStr(Text, Integer [, Text]) Method","slug":"textpadstrtext-integer-text-method","at":0,"chars":2698},{"level":2,"title":"Syntax","slug":"syntax","at":421,"chars":177},{"level":2,"title":"Parameters","slug":"parameters","at":598,"chars":612},{"level":2,"title":"Return Value","slug":"return-value","at":1210,"chars":94},{"level":2,"title":"Remarks","slug":"remarks","at":1304,"chars":218},{"level":2,"title":"Example","slug":"example","at":1522,"chars":1044},{"level":2,"title":"Related information","slug":"related-information","at":2566,"chars":132}],"text":"# Text.PadStr(Text, Integer [, Text]) Method\n> Version: _Available or changed with runtime version 1.0._\nChanges the length of a string to a specified length. If the string is shorter than the specified length, length spaces are added at the end of the string to match the length. If the string is longer than the specified length, the string is truncated. If the specified length is less than 0, an exception is thrown.\n## Syntax\n```al\nNewString :=   Text.PadStr(String: Text, Length: Integer [, FillCharacter: Text])\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 increase or decrease.\nLength\nType: ../integer/integer-data-type\nThe new length of the output string. If Length is less than the length of String, then String is truncated. Otherwise String is expanded with filler characters. If Length is less than 0, then an error is returned.\n*[Optional] FillCharacter*\nType: text-data-type\nThis is a string of length 1. This character is used to fill empty spaces at the end of the output string. If not specified, spaces are used as default. If the length of FillCharacter is not 1, an error is returned.\n## Return Value\nNewString\nType: text-data-type\nA copy of the string with the expected length.\n## Remarks\nIf you omit FillCharacter and String is shorter than Length, then spaces are added at the end of String to match Length.\nIf you omit FillCharacter and String is longer than Length, then String is truncated.\n## Example\n```al\nvar\n    Str1: Text[30];\n    Str2: Text[30];\n    Len1: Integer;\n    Len2: Integer;\n    Text000: Label '13 characters';\n    Text001: Label 'Four';\n    Text002: Label 'Before PadStr is called:\\\\';\n    Text003: Label '>%1< has the length %2\\\\';\n    Text004: Label '>%3< has the length %4\\\\';\n    Text005: Label 'After PadStr is called:\\\\';\nbegin\n    Str1 := Text000;\n    Str2 := Text001;\n    Len1 := StrLen(Str1);\n    Len2 := StrLen(Str2);\n    Message(Text002 + Text003 + Text004, Str1, Len1, Str2, Len2);\n    Str1 := PadStr(Str1, 5); // Truncate the length to 5\n    Str2 := PadStr(Str2, 15, 'w'); // Concatenate w until length = 15\n    Len1 := StrLen(Str1);\n    Len2 := StrLen(Str2);\n    Message(Text005 + Text003 + Text004, Str1, Len1, Str2, Len2);\nend;\n```\nThe first message window displays the following:\nBefore PadStr is called:\n>13 characters\\< has the length 13\n>Four\\< has the length 4\nThe second message window displays the following:\nAfter PadStr is called:\n>13 ch\\< has the length 5\n>Fourwwwwwwwwwww\\< has the length 15\n## Related information\ntext-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}