Automating QTP Test Automation Home Automation Articles Downloads QTP Gotchas Links Books Contact About Site Map
String Function - Extract NThis function extracts the Nth occurence of a substring from a target-string delimited by a from-string and a to-string. Download it Here (right-click and then save target as). (NOTE - you can just cut & paste from below, but the formatting will have multiple spaces instead of tabs).
'=========================================================================
Function zStr_ExtractN(sInput, iPos, sFrom, sTo) Dim iLoop, iLen, iPosn, sLine 'Find the position of the Nth occurence of the from string... sLine = sInput iLen = Len(sFrom) For iLoop = 1 To iPos iPosn = inStr(sLine,sFrom) If iPosn = 0 Then Print "zStr_ExtractN - Failed - From String Not Found - occurence: " & cStr(iLoop) zStr_ExtractN = "" Exit Function End If sLine = Mid(sLine,iPosn + iLen) Next iPosn = inStr(sLine,sTo) If iPosn = 0 Then Print "zStr_ExtractN - Failed - To String Not Found" zStr_ExtractN = "" Exit Function End If zStr_ExtractN = Left(sLine,iPosn-1) End Function '========================================================================= |