web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / axility.NET / str2con and leading zeros

str2con and leading zeros

Volker Breitkopf Profile Picture Volker Breitkopf

If you pack and unpack strings that have leading zero values you are in danger of running into issues because these values might be changed:

static void str2ConLeadingZeros(Args _args)
{
    container con = ['0123', 'OneMoreValue'];
    str s = con2Str(con);
    con = str2con(s);
    info(conPeek(con, 1));
}

This little job shows the issue: The value 0123 is changed to 123 by the str2con call because there’s a type conversion from string to integer. From experience you have leading zero values often in case of customer Ids and suchlike that were migrated from legacy systems. So you really need to be careful with that!

The solution is to simply use str2con_RU (resp. Global::str2con_RU) instead of str2con:

static void str2ConLeadingZeros(Args _args)
{
    container con = ['0123', 'OneMoreValue'];
    str s = con2Str(con);
    con = str2con_RU(s);
    info(conPeek(con, 1));
}

In this case the value 0123 remains.

However I have no idea why this is a function that relates to the Russian internationalization (recognizable by the suffix RU) :)

Comments

*This post is locked for comments