Thursday 1 August 2013

How to sort the array of string in QTP ?

Sometimes when you are testing a application, you need to check that the values are in sorted order.

Here is a sample program that sorts the array of string using strComp function in QTP.

Example -

a = array("bangalore","surat","Pune",1)

For i=0 to ubound(a)

For j=0 to ubound(a)
If strComp(a(i),a(j),1) < 0  Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next

Next

For i=0 to  ubound(a)

   print a(i)
  'It will print 1,bangalore, Pune, surat

Next


Please note that above example will sort the array in ascending order. To sort the array in descending order, you have to use below Code.

a = array("bangalore","surat","Pune",1)

For i=0 to ubound(a)

For j=0 to ubound(a)
If strComp(a(i),a(j),1) > 0  Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next

Next

For i=0 to  ubound(a)

   print a(i)
  'It will print  Pune, surat,bangalore,1

Next

More interview questions and answers on strings in QTP
More interview questions and answers on arrays in QTP are given below.
  1. What is the difference between dictionary and array in QTP?
  2. How to create dynamic 2 dimensional array in QTP?
  3. How to sort array of strings in qtp?
  4. How to create array of dictionary in qtp?
  5. How to define or declare array in qtp?
  6. How to return array from function in qtp?
  7. How to find the length of array in qtp?
  8. How to find the size of array in qtp?
  9. Explain the ubound function in qtp.
  10. Explain the split function in qtp with example.
  11. What is dotnetfactory object in qtp?

Please give your inputs, suggestions, feedback to Us. 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.