community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

Dynamics 365 Business Central: How to pad a string to a specified length with a character (GetPaddedString)

GetPaddedString is a method in Business Central's StringConversionManagement codeunit that fills a string with a specified character until it reaches a desired length, supporting both left and right justification.

post Dynamics 365 Lab

Yun Zhu · 2026-11-26 · 258 words · about 1 min

"there is already a very simple method in the standard codeunit 47 StringConversionManagement that can do this: GetPaddedString()."

Key points

  • GetPaddedString pads strings by adding a character to reach a target length
  • Left justification adds padding characters to the right, right justification adds them to the left
  • If the original string exceeds the pad length, it is not truncated
  • The method is built into standard codeunit 47 StringConversionManagement

Quotes

  • “there is already a very simple method in the standard codeunit 47 StringConversionManagement that can do this: GetPaddedString().” (Identifies the built-in method developers should use instead of writing custom padding logic)
  • “If the original string is already longer than PadLength, GetPaddedString() does not truncate the string.” (Clarifies important behavior: the method preserves longer strings without cutting them)

AL objects mentioned

As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.

No source states these links: they share an object, a model read them, or a person found the same subject.

Heads up

  • gotcha: “If the original string is already longer than PadLength, GetPaddedString() does not truncate the string.” (about codeunit StringConversionManagement)

Context

  • Features: GetPaddedString, string padding, character fill, left justification, right justification

Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.