How to Delete Characters and Space from String by using DELCHR Function in BC D365

Delete Characters and Space from String by using DELCHR Function:

(1) In this blog, we will get to know about the use of the DELCHR function in BC D365. It is used to delete characters and spaces from the string. It is mainly used when removing a special character from the string.

(2) Syntax of DELCHR:

NewString := DELCHR(String[, Where][, Which])

(3) Note: The DelChr method is case-sensitive. If you omit the Which parameter, then the method deletes spaces from String.

(4) Now let’s take examples, as shown below.

  • Example 1→ By using “<>”, as shown.
DELCHR Function Code 1

The method deletes every T and s that is either the first or last character in String. The message is: Output is: his is a Solution

  • Example 2→ By using “=”, as shown.
DELCHR Function Code 2

The method deletes every i and s from String. The message is: Output is: Th a Soluton

  • Example 3→ By using “>”, as shown.
DELCHR Function Code 3

If o, n, s is the last character in String, the method deletes them. The message is: Output is: This is a Soluti

  • Example 4→ By using “<”, as shown.
DELCHR Function Code 4

If T, h, i, or space is the first character in String, the method deletes them. The message is: Output is: s is a Solution

  • Example 5→ w/o using “Which”, as shown.
DELCHR Function Code 5

The method removes any spaces from the start of String. The message is: Output is: This is Solution

  • Example 6→ w/o using “Which” and “Where”, as shown.
DELCHR Function Code 6

The method removes any spaces from the String. The message is: Output is: ThisisaSolutions

(5) Remarks from Microsoft, as below.

  • If you omit the Which parameter, then the method deletes spaces from String based on the contents of the Where parameter as follows:
    1. If Where contains =, then all the spaces are deleted from String.
    2. If Where contains <, then all the spaces at the start of String are deleted.
    3. If Where contains >, then all the spaces at the end of String are deleted.
    4. If Where contains any other character, then an error is returned.
    5. If Where is empty, then String is returned unchanged.
  • If you use the Where and the Which parameters, then the method deletes from String the characters that are contained in the Which parameter based on the contents of the Where parameter as follows:
    1. If Where contains =, then every occurrence of the characters in Which are deleted from String.
    2. If Where contains <, then the characters in Which are only deleted if they occur at the start of String.
    3. If Where contains >, then the characters in Which are deleted only if they occur at the end of String.
    4. If Where contains any other character, then an error is returned.
    5. If Where is empty, then String is returned unchanged.
    6. If Which is empty, then String is returned unchanged.

The Which parameter contains an array of the characters that you want to delete. The order of the characters is of no significance. If String contains a character that is specified in Which, it is deleted from String.


How to Convert or Replace Characters from String by using CONVERTSTR Function in BC D365
Creation of Inventory Setup in D365 BC
Reverse Purchase Receipt in Business Central D365
Creation of Number Series in Business Central
Creation of Manufacturing Setup in D365 Business Central
Setting Up Manufacturing– Microsoft Docs

Leave a Reply