Axaptapedia is now maintained by AgileCadence For more information please click here.
Padding strings
From Axaptapedia
Axapta provides us with an easy way to pad strings with extra characters.
A common situation where this is required is use a "fake" number sequence inside Axapta. If you wish to increment a counter, but store or display it as a string such as "NUM-00001", "NUM-00002" etc then padding the counter with zeros is required.
We can use the strRFix() and strLFix() methods to achieve this. <xpp> int i = 1; str padded; str finalResult;
padded = strRFix(int2str(i), 5, "0"); // Create a string, with a length of 5, ending with the value of i and padded with zeros finalResult = strFmt("NUM-%1", padded); </xpp>
This will populate finalResult with NUM-00001
If we use strLFix instead of strRFix, it will pad to the right with zeros, giving us NUM-10000