Sunday, July 12, 2015

Some string functions used in Axapta:

How to find a string in Ax:

Syntax:

int strFind(
    str _text,
    str _characters,
    int _position,
    int _number)


Ex:
strFind(“abcdef”, “D”, 3, 02) //Returns 4.
  • strFind(“abcdef”, “Bf”, 3, -2) //Returns 2.
  • strFind(“abcdef”, “Z”, 3, 2) //Returns 0.
  • strFind("ABCDEFGHIJ","KHD",1,10); //Returns the value 4 (the position where "D" was found).
  • strFind("ABCDEFGHIJ","KHD",10,-10); //Returns the value 8 (the position where "H" was found).

  • How to search a specific character in String Ax:

    Syntax:

    int strScan(   str _text1, str _text2,    int _position,    int _number)

    Ex:

    //find the current item
        workingItem = Tree.getItem(Tree.getSelection());
        objectId = workingItem.text(); //objectId = "OBJ-0000021: Object Test 1- OBJ"
       
        super();  
        found = strscan(objectId, ":", found, strlen(objectId));
        If (found!=0)
        {
            objectIdActual = subStr(objectId,1,found-1);
            select RecId from objectTable1
            Index ObjectIdx
                where objectTable1.ObjectID == objectIdActual;
            objectBOM.ValidTimeStateUpdateMode (ValidTimeStateUpdate::Correction);
            ttsBegin;
            select forUpdate validTimeState(dateToday) * from objectBOM
                where objectBOM.RecId == element.args().record().RecId; //mroobject.RecId;
            objectBOM.Object = objectTable1.RecId;
            objectBOM.update();
            ttsCommit;
        }

    How to Retrieves part of a string in Ax:

    syntax:
    str subStr(str _text, int _position, int _number)

    Ex:

    subStr("ABCDEFGHIJ",3,5); //Returns the string “CDEFG”.
    subStr("ABCDEFGHIJ",7,-4); //Returns the string “DEFG”.
    subStr("abcdef"),2,99) //Returns the string "cdef".
    subStr("abcdef",2,3) //Returns the string "bcd".
    subStr("abcdef",2,-3); //Returns the string "ab".

    OR

    void test()
    {
    str Name;
    str Result;
    ;
    Name="MED";
    Result=substr(name,1,1);
    info(strfmt("The original Name : %1,the sub string Result : %2",Name,Result));
    }

    Find Starting and ending positions using TextBuffer Class for SubStr():

    int pos;
    TextBuffer textBuffer;

    textBuffer = new TextBuffer();
    textBuffer.setText("ABC DEF GHI JKL MNO ABC ABC");
    pos = 0;

    while (textBuffer.find("ABC",pos))
    {
        print "String found at position: ", textBuffer.matchPos();
        pause;
        pos = textBuffer.matchPos()+1;
    }

    Regular Expressions in Ax:

    http://mybhat.blogspot.in/2012/06/dynamics-ax-regular-expression-match.html





    No comments: