onsdag den 21. april 2010

Useful function for left trimming 0's in a string.

A colleague of mine made this little function.
It strips leading 0's in a string.
The string may only be a 1000 characters long, but that can be modified by changing 1000 to an other value.

static TempStr strLtrim0(TempStr txt,str 1 trim = '0')
{
int i = strNfind(txt,trim,1,1000);
return i ? subStr(txt,i,1000) : '';
}

2 kommentarer:

  1. Hi,
    using strings in x++ normally sized 1000 chars,
    but there are exceptions...
    http://www.crazy-club.de/blog/2010/03/secrets-of-datatype-string/

    SvarSlet
  2. Hi,

    You can use TrimStart for this as well.
    Like this:

    System.String myString2Trim="0000123-456-000-789";
    System.String trimChars="0";
    ;
    info(myString2Trim.TrimStart(trimChars.ToCharArray()));

    (PS: Like your blog!)

    Regards,

    Willy (blog at http://dynamics-ax-live.blogspot.com)

    SvarSlet