Тема: axaptapedia: Match
Показать сообщение отдельно
Старый 30.06.2009, 17:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,644 / 848 (80) +++++++
Регистрация: 28.10.2006
axaptapedia: Match
Источник: http://www.axaptapedia.com/Match
==============

Summary: New page: Here is a method for searching (matching) text in the classical style: If for instance the InventTable must be searched for records whos item name contains the text MUSTER, this method ca...

Here is a method for searching (matching) text in the classical style:

If for instance the InventTable must be searched for records whos item name
contains the text MUSTER, this method can be called with the parameters:

X++:
if (myMatch('*MUSTER*', inventTable.Itemname))
{
    // Then do something
}

The method return true if a match was found and false otherwise.


X++:
static boolean myMatch(str _matchKey, str _text)
{
    str     matchKey        = _matchKey;
    str     text            = _text;
    str     tokKey;                             // Match Key Token  -  Holds actual Character being examined
    str     tokText;                            // Text Token       -  Holds actual Character being examined
    str     laTok;                              // Look Ahead Token -  Holds Character one Positition after Token Character
    int     lenKey;                             // Key Length
    int     lenText;                            // Text Length
    int     incKey;                             // Incrementor for Key
    int     incText;                            // Incrementor For Text
    int     laKey;                              // Look Ahead Incrementor for Key
    boolean ret             = true;
    ;

    #define.WC_MANY ('*')
    #define.WC_ONE  ('?')

    if (!matchKey)
        matchKey = #WC_MANY;

    lenKey  = strlen(matchKey);
    lenText = strlen(text);
    incText = 1;

    for (incKey = 1; incKey  lenText)
            ret = false;

        switch (tokKey)
        {
            case #WC_MANY   :
                if (incKey < lenKey)
                {
                    laKey   = incKey + 1;
                    laTok   = substr(matchKey, laKey, 1);
                    if (strscan(text, laTok, incText, strlen(text)))
                    {
                        incText = strscan(text, laTok, incText, strlen(text));
                        if (!myMatch(
                                     substr(matchKey, incKey + 1, strlen(matchKey)),
                                     substr(text, incText, strlen(text))
                                   ))
                        {
                            incKey--;
                            incText++;
                        }
                        else
                        {
                            return true;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return true;
                }
                break;
            case #WC_ONE    :
                incText++;
                break;
            default         :
                if (tokKey == substr(text, incText, 1))
                {
                    incText++;
                }
                else
                {
                    return false;
                }
                break;
        }
    }
    if (incText < lenText)
        ret = false;

    return ret;
}


Источник: http://www.axaptapedia.com/Match
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.