D365 Business Central : StringConversionManagement Codeunit

There are lots of Management Codeunit in D365 Business Central. Let us talk about one of them which is StringConversionManagement Codeunit. There are currently four procedures in this Codeunit that you can call:
– WindowsToASCII
– GetPaddedString
– RemoveDecimalFromString
– RemoveNonAlphaNumericCharacters
Let’s look at it one by one.

WindowsToASCII
This procedure is used to convert text into Ascii characters. What is Ascii ? It’s the first set character encoding standard for electronic communication. It was first launched in 1963.
This procedure is currently being used when exporting Payment Remittance data.


GetPaddedString
This procedure can be used to pad a string with any character that we specify. The text must be under 250 characters. This procedure is a bit useless now because we have Text.PadLeft and Text.PadRight method.
Let’s test this procedure by running below code.

InputText := 'ABC123';
NoOfChars := 10;
PadCharacter := '-';
Message('Left Justification: \' + StringConversionManagement.GetPaddedString(InputText, NoOfChars, PadCharacter, Justification::Left) + '\' +
        'Right Justification: \' + StringConversionManagement.GetPaddedString(InputText, NoOfChars, PadCharacter, Justification::Right));

Result:


RemoveDecimalFromString
This procedure name is a bit misleading and it doesn’t seem like it is being used anywhere.
When the input text is not decimal and the text length is bigger than Pad Length, it will always return the text as it is.
If the input text is decimal, it will remove non-numeric characters and pad the text.
I can’t think of any scenario where this procedure would be useful.

Let’s test it. When we run it with below parameters, it will result in ABC123 because our input text is not decimal.

StringToModify: ABC123
PadLength: 10
PadCharacter: –
Justification: Left
Result: ABC123

However, if we use decimal in the text, we will get 123456—-.

StringToModify: 1234.56
PadLength: 10
PadCharacter: –
Justification: Left
Result: 123456—-.

Below is the test result with left and right justification.


RemoveNonAlphaNumericCharacters
We can use this procedure to remove non alpha numeric characters from text. It is currently being used in Transformation Rule and in exporting Item Picture.

Let’s test this by running below code.

InputText := '123~ ABC#9';
Message(StringConversionManagement.RemoveNonAlphaNumericCharacters(InputText));

Result:

Sample GitHub code: Here.

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

1 Response

  1. 26 January 2023

    […] Source : That NAV Guy Read more… […]

Leave a Reply

Your email address will not be published. Required fields are marked *