preload

GetTokenByKeyword (QTP, TestComplete, VBScript)

Posted by Albert Gareev on Mar 06, 2012 | Categories: Source codeText Data

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

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.