Wednesday 20 November 2013

Explain Global property of the RegExp object in QTP

Global property is used to tell how many matches should be found in the given string.

Examples to understand the global property are given below.

'**********************************************
'With global = false
'When we set the global property to false, we get only first match
'**********************************************
  Set regExpObject = New RegExp  
  search_string = "Arjun tendulkar is the son of sachin tendulkar"
  regExpObject.Pattern = "tendulkar"

  regExpObject.Global = false      

  set matches = regExpObject.execute(search_string)

   print matches.count

'**********************************************
'output is 1
'**********************************************



'**********************************************
'With global = true
'When we set the global property to true, we get all matches
'**********************************************
  Set regExpObject = New RegExp  
  search_string = "Arjun tendulkar is the son of sachin tendulkar"
  regExpObject.Pattern = "tendulkar"

  regExpObject.Global = true

  set matches = regExpObject.execute(search_string)

   print matches.count

'**********************************************
'output is 2
'**********************************************
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.