I have written a function to get sublist from a list of items. I have done for STRING type. You can try for ANYTYPE data type.Its usage is similar to SubString. See the following code snippet.
Silktest code sample: GetSubList
[+] public LIST OF STRING GetSubList(LIST OF STRING lsInput, STRING sFirst optional, STRING sLast optional, Boolean bMatch optional) [ ] //To get String list between sFirst and sLast [ ] //If sFirst is NULL or "", SubList will be taken from first item of list [ ] //If sSecond is Null or "", SubList will be taken upto last item of list [ ] //bMatch - FALSE means exact match, TRUE means Partial Match [ ] Integer iCount, iItem [ ] Boolean bFirst = FALSE [ ] Boolean bLast = FALSE [ ] LIST OF STRING lsReturn = {} [ ] [-] if (IsNull(bMatch)) [ ] bMatch = FALSE [-] if (IsNull(sFirst) || (sFirst == "")) [ ] bFirst = TRUE [ ] [ ] iCount = ListCount(lsInput) [-] for iItem=1 to iCount [-] if !(bFirst) [-] if !(bMatch) [-] if (sFirst == lsInput[iItem]) [ ] bFirst = TRUE [ ] ListAppend(lsReturn,lsInput[iItem]) [-] else [-] if (Len(sFirst) <= Len(lsInput[iItem])) [-] if (MatchStr("*{sFirst}*",lsInput[iItem])) [ ] bFirst = TRUE [ ] ListAppend(lsReturn,lsInput[iItem]) [+] else [-] if !(bLast) [ ] ListAppend(lsReturn,lsInput[iItem]) [-] if !(IsNull(sLast)) [-] if !(bMatch) [-] if (sLast == lsInput[iItem]) [ ] bLast = TRUE [-] else [-] if (MatchStr("*{sLast}*",lsInput[iItem])) [ ] bLast = TRUE [-] else [ ] break //Exit from for loop [ ] [ ] return lsReturn [ ]
No comments:
Post a Comment