How to do string left or right padding in X++

This article will explain how you can do string padding with zeros or space with the specified length either left padded or right padded in X++. Often we have a requirement that the desired string should be of specific length (say 10) and if it is not of that length, it should be prefixed with 0. A practical example would be that we need to export bank or vendor txt file with the specific configuration at desired places for a string with a specific length from ERP.

To do left padding, strRFix function can be used and to do right padding, strLFix function can used

Syntax

str strRFix(str _str,int _length,char _char= ‘ ‘)

str strLFix(str _str,int _length,char _char= ‘ ‘)


str value = 'Demo';

//strRFix

Info(strRFix(value,7,'0'));// this will info '000Demo'

Info(strRFix(value,7));// this will info '   Demo' // 3 parameter is optional with default value of space

 

//strLFix

Info(strLFix(value,7,'0'));//this will info 'Demo000'

Info(strLFix(value,7));//this will info 'Demo   ' //3 parameter is optional with default value of space 

Reference : https://axparadise.com/how-to-do-left-or-right-string-padding-in-x-ax/

Comments

Popular posts from this blog

SSRS Report using Controller , Contract and RDP classes in D365

Exporting data to Excel through X++ code

COC for Form level method

How to pass the parameter from one form to another in Dynamic365

Multi Select Lookup in SSRS Report in D365