AX2012 StrSplit Function with list Iterator in X++

May be this is useful for lot of persons while importing or exporting for splitting the string and get the string of the required position

private str strSplit(str _splitString,str _splitchar,int _pos)
{
    List strlist=new List(Types::String);
    ListIterator    iterator;
    container       packedList;
    ;
    strlist=strSplit(_splitString,_splitchar);
    iterator = new ListIterator(strlist);
    while(iterator.more())
    {
        packedList += iterator.value();
        iterator.next();
    }
    return conPeek(packedList,_pos);
}

To call you can use like following


str strvalue="Test|Test2|Test3|Test4";
info(createProduct.strSplit(strvalue,"|",2));

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.