How to find the particular word in text file and how to split and capture total line of the founded word using vb scripting?

Normally has many webtable and we can extract a lot of information using webtable methods in QTP.In this post we will discuss various methods by which we can used for webtable object. HyperLink and click the link and the password is 1234 to get the page .


here i want find the HyperLink and password.
my output should like :....
1: HyperLink= "http://google.com/users/login?returnurl=%2fquestions%2fask#create-account"
2: password= 1234

Questions by Baleesh

Showing Answers 1 - 6 of 6 Answers

Anu

  • Jan 24th, 2014
 

You can take the help of regexp object and find the matches as below

Code
  1. open the text file to search the word in

  2. set fso = createobject("scripting.filesystemobject")

  3. set mytxt = fso.OpenTextFile("C:Usersanu.bajpaiDesktopf1.txt")

  4.  

  5. c_LineMatch=0

  6. o_wordMatch =0

  7.  

  8. regex for the word to be searched

  9. Set myregex = new RegExp

  10. with myregex

  11.         .Global = true

  12.         .Pattern = "QTP"

  13.         .IgnoreCase = True

  14. End With

  15.  

  16.  

  17. Do until mytxt.AtEndOfStream

  18.         Read one line at a time

  19.         str1 = mytxt.ReadLine

  20.         Set colMatches = myregex.Execute(str1)

  21.         no of words matched in the Text file

  22.         o_wordMatch = o_wordMatch +colMatches.Count

  23.                        

  24.                        

  25.         Count no of lines which have the words to search       

  26.         if colMatches.Count > 0 then

  27.                 c_LineMatch=c_LineMatch+1

  28.         end if

  29. Loop

  30.  

  31.  

  32.  

  33. No of words matxhed in the text file

  34. Msgbox o_wordMatch

  35. No of lines having the words to be searched

  36. msgbox c_LineMatch

  37.  

  Was this answer useful?  Yes

Use below

Code
  1. open the text file to search the word in

  2. set fso = createobject("scripting.filesystemobject")

  3. set mytxt = fso.OpenTextFile("C:Usersanu.bajpaiDesktopf1.txt")

  4.  

  5. c_LineMatch=0

  6. o_wordMatch =0

  7.  

  8. regex for the word to be searched

  9. Set myregex = new RegExp

  10. with myregex

  11.         .Global = true

  12.         .Pattern = "QTP"

  13.         .IgnoreCase = True

  14. End With

  15.  

  16.  

  17. Do until mytxt.AtEndOfStream

  18.         Read one line at a time

  19.         str1 = mytxt.ReadLine

  20.         Set colMatches = myregex.Execute(str1)

  21.         no of words matched in the Text file

  22.         o_wordMatch = o_wordMatch +colMatches.Count

  23.                        

  24.                        

  25.         Count no of lines which have the words to search       

  26.         if colMatches.Count > 0 then

  27.                 c_LineMatch=c_LineMatch+1

  28.         end if

  29. Loop

  30.  

  31.  

  32.  

  33. No of words matxhed in the text file

  34. Msgbox o_wordMatch

  35. No of lines having the words to be searched

  36. msgbox c_LineMatch

  37.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions