February 10, 2008

Tip12 - To match a string against list of string

In Silktest, we do not have a built-in function to match a item by wild cards with a List of items. In this scenario, you can use following code snippet. Here I have declared as string and if you want to use different data types, declare as ANYTYPE.


[-] public Integer MatchList(String sPattern, LIST OF STRING lsInput)
[ ] //To match one string with any item in list of strings
[ ] //Returns the item value(integer)
[ ] Integer iCount, iItem
[ ] String sData, sTemp
[ ] Integer iReturn = 0
[ ]
[ ] iCount = ListCount(lsInput)
[-] for iItem=1 to iCount
[-] if (MatchStr(sPattern,lsInput[iItem]))
[ ] iReturn = iItem
[ ] break
[ ]
[ ] return iReturn

0 comments: