GetTokenByKeyword (QTP, TestComplete, VBScript)
Parent page: Service Functions – String (QTP, VBScript)
Description
Get token string from the source string. Position is relative, defined by another token-keyword and a number.
Implementation
Public Function GetTokenByKeyword(ByVal strSource, ByVal chrDelimiter, ByVal strKeyword, ByVal intNumber, ByRef strToken) Dim Tokens, intCount, intIndex Dim i, boolRC Tokens = Split(strSource, chrDelimiter) intCount = UBound(Tokens)+1 intIndex = -1 For i=0 To intCount-1 If Regex_Test(Tokens(i),strKeyword) Then intIndex = i Exit For End If Next If intIndex = -1 Then strToken = "" GetTokenByKeyword = False Exit Function End If If (intIndex+1+intNumber) > intCount Then strToken = "" GetTokenByKeyword = False Exit Function End If If (intIndex+1+intNumber) < 0 Then strToken = "" GetTokenByKeyword = True Exit Function End If strToken = Tokens(intIndex+intNumber) GetTokenByKeyword = True End Function