Showing posts with label Regular Expressions. Show all posts
Showing posts with label Regular Expressions. Show all posts

Sunday, 27 April 2014

QTP - UFT - How to count number of occurances of a string in a statement






We can use  regular expression.

Syntax
inputstring = "This String has multiple statements and each statement has multiple occurrences"
Set o1 = new RegExp
o1.pattern = "statement"
o1.ignorecase = true
o1.global = true
Set r1 = o1.execute(inputstring)
msgbox r1.count


QTP - UFT - How to use regular expressions?



How to use regular expression - code please to find a some sting in a large string
Regular expressions are very handy with Scripting and can be used in multiple ways. I would like to present once scenario on its usage.

Syntax
inputstring = "This Blog helps you with learn and test your skills on UFT"
Set o1 = new RegExp
o1.pattern = "learn"
o1.ignorecase = true
o1.global = true
Set r1 = o1.execute(inputstring)

For Each Match in r1
  Flag =1
  str = str & Match.firstindex & " - "
 Next
If Flag =1 Then
 msgbox "match found at locations " & str
End If