Inspired by a Microsoft Developer

Yes it happens.

When reading the C/AL code in NAV written by other developers you normally pick up smart way to do things.  Yesterday I got one.

In my solutions I have been using a function to check if a string is numeric and another function to extract the numeric value from a string.


All good and well.  Working fine so far.  But if you can write each function with a single line, would that not be better ?


Thanks for the inspiration Microsoft.

11 Replies to “Inspired by a Microsoft Developer”

  1. Hi Gunnar,
    How about this one?

    IsNumeric(CheckString : Text) : Boolean

    Were “DummyDecimal” is a local variable of type “Decimal”


  2. Hi,
    imho good but not perfect. think about decimals and seperators. 1,234.56 would’nt match.
    Maybe this whould be better:


      1. The Problem wirh evaluate is the using of a specific culture
        e.g. 1’234.56 is a valid number in switzerland but would fail in an evaluate on a en-us Server configuration.

  3. This is a good one, Gunnar. I stumbled into this while cleaning illegal characters from file names I was creating from mixed input. A slightly different implementation using a text constant.

    ObjectFileName := DELCHR(Object.Name,’=’,Text007)), 1, MAXSTRLEN(ObjectFileName));

    Where Text007 is all the illegal characters: :”/|?*’

  4. IsNumeric will return FALSE if the CheckString is ‘1.234’ or ‘2,00’.
    Normally I would do it like this:

    IF EVALUATE(DecimalValue,CheckString) THEN
    EXIT((DecimalValue MOD 1) = 0)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.