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 arrays in QTP are given below.
Please give your inputs, suggestions, feedback to Us. We value your thoughts.
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
- What are the different string functions in QTP?
- How to extract the digits from given string in QTP?
- How to sort the array of strings in qtp
- How to get the first character in string in QTP?
- How to convert the string into upper case in QTP?
- How to get the last character from the string in QTP?
- How to replace the string in qtp?
- How to check if substring exists in QTP?
- Explain right, mid and left functions in qtp?
- How to remove the spaces from string in qtp?
- What are the trim functions in qtp?
- Explain replace function in qtp with example.
- Explain the split function in qtp with example.
- Explain lcase and ucase functions in qtp.
- What is the len function in qtp?
- Give the example of instr function in qtp
- What is the difference between dictionary and array in QTP?
- How to create dynamic 2 dimensional array in QTP?
- How to sort array of strings in qtp?
- How to create array of dictionary in qtp?
- How to define or declare array in qtp?
- How to return array from function in qtp?
- How to find the length of array in qtp?
- How to find the size of array in qtp?
- Explain the ubound function in qtp.
- Explain the split function in qtp with example.
- 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