str2Enum Function

Converts a localized string into one of the integer values of the specified enumeration type.


enum str2Enum(enum _type, str _text)

Parameter

Description

_type

A variable declared as the enumeration type to which to convert the string.

_text

The localized text to use as the name of the enumeration value.

The integer value of the specified string.

An appropriate value for the _text parameter is enum2Str(BankAccountType::SavingsAccount).

The following example shows the appropriate way to use the str2enum function with the enum2str function. When your code inputs a string representation of an enumeration value into the str2enum function, that string should come from a call to the enum2str function that occurs on the same Microsoft Dynamics AX system. This prevents a mismatch between languages.

static void str2EnumAcrossLangs(Args _arg)
{
    BankAccountType bat;
    str sEnumValueNameLocalized;
    int nInt;
    ;
    sEnumValueNameLocalized = enum2str
        (BankAccountType::SavingsAccount);
    info("Localized friendly string: "
        + sEnumValueNameLocalized);

    nInt = str2Enum(bat, sEnumValueNameLocalized);
    info("nInt = " + int2str(nInt));
/********** Actual Infolog output
Message (04:32:09 pm)
Localized friendly string: Savings account
nInt = 1
**********/
}

Community Additions

ADD
Show: