mandag den 20. juli 2009

Tokenizing a string

How to tokenize a string.

In Java you can use an object of the stringTokenizer class to break up a string in to tokens.
Dynamics AX has a handy class called TextBuffer with which you can achieve a similar effect.
This example shows how (the code is written as a job):


static void Job7(Args _args)
{
    TextBuffer t;

    t = new TextBuffer();
    t.ignoreCase(true);
    t.regularExpressions(false);
    // Set the text to break in to tokens
    t.setText("When I find myself in times of trouble, mother Mary comes to me, speaking words of wisdom, let it be. And in my hour of darkness she is standing right in front of me, speaking words of wisdom, let it be.");

    // The delimiter to search for when finding tokens is space
    while (t.nextToken(false," "))
    {
        info(t.token());
    }
}

Ingen kommentarer:

Send en kommentar