Tuesday, April 7, 2015

Useful functions for container

conLen:

conLen function is used to get the container length.

conPeek:

conPeek is used to get the container content by index. Note: index starts by 1.

conIns:

conIns function is used to insert one or more elements into a container. For example:
static void Hari_Test_ConIns(Args _args)
{
    container   c;
    int         i;
    c = [3, 'third'];
    c = conIns(c, 1, 1, 'first', 2, 'second');
   
    for(i = 1; i <= conLen(c); i++)
    {
        info(strFmt('%1', conPeek(c, i)));
    }
}

Result:
1
first
2
second
3
third

Note: += is faster than conIns function. We can use conIns when you want to insert the element in the particular index.

conDel:

conDel function is used to delete the one or more elements from the container. For example:
static void Hari_ConDel(Args _args)
{
    container   c;
    int         i;
    c = [3, 'third'];
    c = conIns(c, 1, 1, 'first', 2, 'second');
    c = conDel(c, 5, 2);
    for(i = 1; i <= conLen(c); i++)
    {
        info(strFmt('%1', conPeek(c, i)));
    }
}

Result:
1
first
2
second

conFind:

conFind function is used to find the sequence elements in the container. For example:
static void Hari_ConFind(Args _args)
{
    container c = ["item1", "item2", "item3"];
    int i, j, k, l;
    ;

    i = conFind(c, "item2");
    j = conFind(c, "item1", "item2");
    k = conFind(c, "item1", "item3");
    l = conFind(c, "item4");
   
    print "Position of 'item2' in container is " + int2Str(i);
    print "Position of 'item1 item2' in container is " + int2Str(j);
    print "Position of 'item1 item3' in container is " + int2Str(k);
    print "Position of 'item4' in container is " + int2Str(l);
    pause;
}

Result:
Position of 'item2' in container is 2
Position of 'item1 item2' in container is 1
Position of 'item1 item3' in container is 0
Position of 'item4' in container is 0

conNull:

conNull function is used to empty or dispose the contents of the container.

conPoke:

conPoke function is used to replace the contents of the container from the particular index. For example:
static void Hari_TestJob(Args _args)
{
    container c1 = ["item1", "item2", "item3"];
    container c2;
    int i;

    void conPrint(container c)
    {
        for (i = 1 ; i <= conLen(c) ; i++)
        {
            print conPeek(c, i);
        }
    }
    ;
    conPrint(c1);
    c2 = conPoke(c1, 2, "PokedItem", "Test");
    print "";
    conPrint(c2);
    pause;
}

Result:
item1
item2
item3

item1
PokedItem

Test

No comments :

Post a Comment