Micro Focus QTP (UFT) Forums
how to find a particular text in a text string - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: how to find a particular text in a text string (/Thread-how-to-find-a-particular-text-in-a-text-string)



how to find a particular text in a text string - pjavvaru - 06-03-2010

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..


RE: how to find a particular text in a text string - sreekanth chilam - 06-03-2010

Hi ,

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

Try it out , it would work fine. Smile


RE: how to find a particular text in a text string - chanda Hemke - 06-04-2010

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


RE: how to find a particular text in a text string - jsknight1969 - 06-04-2010

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.