Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to find a particular text in a text string
#1
Solved: 10 Years, 9 Months, 1 Week ago
I need to read version number from a text displayed either in popup or dialog window or flash player..etc

I used
Code:
vistext= windows("a").webobj("b").getvisibletext
( this is not exactly but i used getvisibletext)

if instr(1,vistext,"10,5") > 0
pass
then
fail

my question is the text on that dialog box behaves differently in different machines. in some machines, it puts ","(comma) beside versions like 10,5,2,3 etc.. in some it is 10:5:2:3 , i want to check for both these. how can i do

if instr(1,vistext,"10,5","10:5")>0 - Can v write something like this.. becoz i want to check for both. 10,5 and also 10:5

i hpe you understood my question.
help me plz..
Reply
#2
Solved: 10 Years, 9 Months, 1 Week ago
Hi ,

In your case you can use "Instr" with the Logical Operators such as "OR","AND".

Try it out , it would work fine. Smile
Reply
#3
Solved: 10 Years, 9 Months, 1 Week ago
Ya according to sreekanth , u can use this as

if instr(1,vistext,"10,5") > 0 Or instr(1,vistext,"10:5") > 0
pass
then
fail
Reply
#4
Solved: 10 Years, 9 Months, 1 Week ago
You can also use regular expressions.
Code:
Dim re, teststring, testresults, showresults
teststring = "10:2:3:1"
Set re = new regexp
re.Pattern = "(\d*[,|:]){3}(\d*)+"
re.Global = true
re.IgnoreCase = true

'boolean test
msgbox re.Test(teststring)


'Get the actual text
set testresults = re.Execute(teststring)
For each match in testresults
    showresults = showresults + match.value
Next
msgbox showresults

This pattern means: 3 sets of numbers of any length separated by a "," or ":" then a final set of numbers of any length.

Changing the separator or adding alpha characters or adding/removing a separator with digits will return a false.

The "Test" method returns a boolean based on the pattern. The "Execute" method will return an array of characters that match in the pattern that you can then parse to get a particular value or concatenate to return the string.

Regular expressions are quite powerful and can be used for many applications in parsing strings.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems with Text color recognition Treirk 0 982 06-17-2019, 12:19 PM
Last Post: Treirk
  How to remove text in the webedit silpavinod 3 13,388 07-12-2018, 11:08 AM
Last Post: vijaychourasiya0109@gmail.com
  text checkpoint properties error alp 0 1,059 11-24-2017, 04:36 PM
Last Post: alp
  How can we get the Windows application Text box background color Using UFT 11.53 Kuppampattu 3 5,674 06-06-2017, 11:12 AM
Last Post: workrohit08
  How to find and change text in PDF document using QTP UFT automation VBscript alexwhite 0 11,907 02-18-2017, 04:20 AM
Last Post: alexwhite

Forum Jump:


Users browsing this thread: 1 Guest(s)