How to use len,Right,left,mid and StrReverse functions in QTP?

In this article we would see the usage of len,left,right,mid and StrReverse functions in QTP.

Functions in qtp

How to find out length of the string in QTP?

To find a length of a string use len function, len function returns the length of the string.

Syntax:

Len (stringname)

Example

Dim Var                                          ‘Variable Declaration’

Var =”Infoyepgroup”                    ‘String “Infoyepgroup” assigned to Variable Var’

lenvar =len(var)                              ‘specify len function to  findout length ‘

msgbox lenvar

 

Output

12                                          ‘Length of ’ infoyepgroup’ Is  12’

Right Function:

Right Function is used to return a specified number of characters from the right side of a string.

Right Function Syntax:

Right (String, Length of the string)

If string value is null, then null value will return, Length of the string is an integer, based on integer value from right hand side value will count.

Example:

Dim Var                                          ‘Variable Declaration’

Var =”Infoyepgroup”                    ‘String “Infoyepgroup” assigned to Variable Var’

Rightvar =Right(var,4)                  ‘specify right function with string and length’

msgbox Rightvar

Output  

“roup”                                                ‘Last 4 characters from the string’

Left Function

Left Function is used to return a specified number of characters from the left side of a string.

Left Function Syntax:

Left (String, Length of the string)

If string value is null, then null value will return.

Example:

Dim Var                                          ‘Variable Declaration’

Var =”Infoyepgroup”                    ‘String “Infoyepgroup” assigned to Variable Var’

Leftvar =Left (var, 4)                     ‘specify left function with string and length’

msgbox Leftvar

Output  

“Info”                                             ‘First 4 characters from the string’

Mid Function

Mid Function returns a specified number of characters from a string based on integer  start value.

Mid Function Syntax:

Mid (String, Start (length of string))

Example:

Dim Var                                          ‘Variable Declaration’

Var =”Infoyepgroup”                    ‘String “Infoyepgroup” assigned to Variable Var’

Midvar =Mid(var, 4)                     ‘specify Mid function with string and length’

msgbox Midvar

Output  

oyepgroup”                                             ‘Starts from 4th character from the string’

 

StrReverse Function

StrReverse is used to reverse the particular string.

Syntax

StrReverse(string1)

Example:

Dim Var                                          ‘Variable Declaration’

Var =”Infoyepgroup”                    ‘String “Infoyepgroup” assigned to Variable Var’

strvar =strreverse(var)                  ‘specify strreverse function to reverse ‘

msgbox strvar

 

Output

Puorgpeyofni                              ‘Infoyepgroup is reversed’

Same Len, Right, Left, Mid and Strreverse functions in qtp can be used in Vb Script as well, type the above codes in notepad and save it as ‘Filename.vbs’ and double click to run it.

Summary
Article Name
How to use len,Right,left,mid and StrReverse functions in QTP?
Description
In the below article we would see the usage of different functions in qtp, examples: len, left, right, mid and StrReverse etc.
Author
Publisher Name
Raghavendra
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *