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.
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.
The method deletes every i and s from String. The message is: Output is: Th a Soluton
- Example 3→ By using “>”, as shown.
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.
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.
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.
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:
- If Where contains =, then all the spaces are deleted from String.
- If Where contains <, then all the spaces at the start of String are deleted.
- If Where contains >, then all the spaces at the end of String are deleted.
- If Where contains any other character, then an error is returned.
- 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:
- If Where contains =, then every occurrence of the characters in Which are deleted from String.
- If Where contains <, then the characters in Which are only deleted if they occur at the start of String.
- If Where contains >, then the characters in Which are deleted only if they occur at the end of String.
- If Where contains any other character, then an error is returned.
- If Where is empty, then String is returned unchanged.
- 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.