Micro Focus QTP (UFT) Forums
Ways to perform extraction - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Ways to perform extraction (/Thread-Ways-to-perform-extraction)



Ways to perform extraction - AAB - 06-01-2012

Can anybody tell how can we extract the current page and total pages value from the expression "Page 4 of 15"? One of the ways that i can think of is using split function but what can be the other ways of doing it?


RE: Ways to perform extraction - AAB - 06-04-2012

Are there any ideas to share by anybody?


RE: Ways to perform extraction - supputuri - 06-04-2012

Hi AAB,

We can do it using regular expression too. Checkout the below code

Code:
input = "Page 22432 of 201222122"

Set objRegExp = New RegExp
objRegExp.Pattern = "[^A-Za-z ]\d*"
objRegExp.Global = True
Set Numbers = objRegExp.Execute(input)
msgbox Numbers.count
For I = 0 to Numbers.Count-1
    If I = 0 Then
        msgbox "Current Page Number: " & Numbers(I)
    ElseIf I = Numbers.Count-1 Then
        msgbox "Total Number of Pages:" & Numbers(I)
    End If
Next
Set Numbers = Nothing
Set objRegExp = Nothing

Let me known if you have any questions.


RE: Ways to perform extraction - AAB - 06-05-2012

Hi supputuri,
Thanks for your help.It gave me another way to look at these matching/extraction issues.
Then i Tried this:
strlocation="D:\Documents and Settings\Desktop\New Folder"
Objective: To extract the folder name and the file path from the above location.
For the folder name i tried the following code:
'***********************************
Code:
Set obj=New Regexp
obj.pattern="[A-Z a-z]*$"
obj.global=True
Set num2=obj.execute(d)
msgbox num2.count
For i=0 to num2.count-1
    msgbox num2(i)

Next
'**********************************
Here the problem that i came across is that if i use the pattern as "[A-Z a-z]*$" then it gives two values in the match collection returned by Execute which are :"New Folder" and "".
So then i changed the pattern to "[A-Z a-z ]*$" and it gave me the correct result but the question is by looking at the input it seems that no additional space is there then why is it required in the regular expression?Please clarify.


RE: Ways to perform extraction - supputuri - 06-05-2012

Hi I did not find any difference by using the specified patterns.

but change the obj.global = False we will get the correct value.