Monday, February 13, 2012

QTP - String Functions

1. String Comparision - StrComp
This function is to compare two strings length and returns the output.

The following function returns an output as 0 if there is no difference found.
It returns 1 if the length of string 1 > string 2
It returns -1 if the length of string 2 > than string 1

Dim Str1, Str2, X
Str1 = 'Sudha'
Str2 = 'Sudha'
X = StrComp(Str1, Str2, X)
msgbox X
Output = 0

Dim Str1, Str2, X
Str1 = 'SudhaTest'
Str2 = 'Sudha'
X = StrComp(Str1, Str2, X)
msgbox X
Output = 1

Dim Str1, Str2, X
Str1 = 'Sudha'
Str2 = 'SudhaTest'
X = StrComp(Str1, Str2, X)
msgbox X

Output = -1

2. String Reverse - StrReverse
This function is to display the disired string characters in reverse order.

Dim Str, X
Str = 'Testing Pond'
X = StrReverse(Str)
msgbox X

Output = dnoP gnitseT

val=1002
x=StrReverse(val)
msgbox x 'Output: 2001

val=#10-10-10#
x=StrReverse(val)
msgbox x 'Output: 0102/01/01

3. LCase/UCase Function
These functions are to convert the string from lower to upper case and upper case to lower case.

Dim X
X = UCase("sudha")
msgbox X

Output - SUDHA

Dim X
X = LCase("SUDHA")
msgbox X

Output - sudha