community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

Dynamics 365 Business Central: How to quickly remove white-space characters from the current Text/String (leading, trailing and all) in AL

This post explains four methods to remove whitespace characters from text strings in AL: TrimStart for leading spaces, TrimEnd for trailing spaces, Trim for both leading and trailing, and DelChr for all whitespace. It includes working code examples showing each method in a test page.

post Dynamics 365 Lab

Yun Zhu · 2025-07-04 · 515 words · about 2 min

"Removes all leading occurrences of a set of characters specified in an array from the current Text object."

Key points

  • TrimStart() removes only leading whitespace characters
  • TrimEnd() removes only trailing whitespace characters
  • Trim() removes both leading and trailing whitespace in one call
  • DelChr() can remove all whitespace characters from anywhere in the string
  • Each method has specific use cases depending on which whitespace needs to be removed

Quotes

  • “Removes all leading occurrences of a set of characters specified in an array from the current Text object.” (Explains what TrimStart does, essential for understanding when to use this method)
  • “Returns a new Text in which all leading and trailing white-space characters from the current Text object are removed.” (Describes Trim’s dual functionality, useful for the most common whitespace removal scenario)

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.

  • page “Remove Spaces”

Not found in BC28-30: page “Remove Spaces”.

Context

  • Features: TrimStart method, TrimEnd method, Trim method, DelChr method, text manipulation
  • Versions: 2023 wave 1

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.