Sponsored Ad

Tuesday, October 12, 2010

QTP: Find the Starting Position of a String in Another String | InStr

Steps to Write String Searching program in QTP:

1. Use InStr to search in string.

2. First parameter is start position (optional), second parameter is string where we need to search, third is searching string, fourth is compare type.

3. There is two type of comparison

  • 0 =  Perform a binary comparison
  • 1 =  Perform a textual comparison

QTP Script to Search in String using VBScript:

<html>
<body>
<script type="text/vbscript">

MyQTP="Software Testing Tutorial for String Search."

msgbox "Testing Location: " & InStr(MyQTP,"Testing") & vbNewline  & "Search i with Starting pos 1: " & InStr(1,MyQTP,"i") & vbNewline  & "Search o Start pos 1 and textual comparison: " & InStr(1,MyQTP,"o",1) & vbNewline & "Binary Comparison: " & InStr(1,MyQTP,"t",0) & vbNewline

</script>
</body>
</html>

Output of String Search Results:

QTP: Find the Starting Position of a String in Another String | InStr

Where to Run This Program:

1. This VBScript Program code either you can use in QTP editor  (code between <script> and </script> tags ) and run it.

2. Write in Notepad, save with .htm extension and run on internet explorer.

0 comments:

Post a Comment

Sponsored Ad

Development Updates

Tech Updates