How to Remove Non-Numeric Characters in a Text in Business Central

Photo by James Orr on Unsplash

How to Remove Non-Numeric Characters in a Text in Business Central

·

1 min read

There are scenarios whereby you are required to sanitize certain data, especially in integration projects, to remove errand text characters before inserting them into the ERP system.

In the "simplified" case below, I will receive a text from a 3rd party solution containing alphanumeric values and I am required to extract only numeric data from it to either send it for further processing or storage.

By using the "DelChr" function, it is possible to do that. A working example is shown below.

var
    sourceText: Text;
    sanitizedText: Text;
begin 
    sourceText := '09643vjhdskjhfAB9080ZXsadf';
    sanitizedText := DelChr(sourceText, '=', DelChr(sourceText, '=', '1234567890')); // result = 096439080
end;