VB Script String Functions
VB Script String Functions
Visit:
www.gcreddy.com
for QTP and VB script Information
Abs Function
Dim num
num=157.56
num=Abs(num)
msgbox num 'Output: 157.56
num=-157.56
num=Abs(num)
msgbox num 'Output: 157.56
Array Function
Ex:
Dim var
gcreddy.com 1
QTP Training
'List of strings
var=Array("Hyderabad","Chennai", "Nellore")
msgbox var(0) 'output: Hyderabad
msgbox var(1) 'output: Chennai
msgbox var(2) 'output: Nellore
IsArray Function
x=isArray(var2)
msgbox x
IsDate
Examples:
Dim myDate,x
myDate=100
x=IsDate(myDate)
msgbox x 'Output: False
myDate="India"
gcreddy.com 2
QTP Training
x=IsDate(myDate)
msgbox x 'Output: False
myDate=#10/05/2010#
x=IsDate(myDate)
msgbox x 'Output: True
myDate=#10-05-2010#
x=IsDate(myDate)
msgbox x 'Output: True
myDate=#10-05-10#
x=IsDate(myDate)
msgbox x 'Output: True
myDate=10-05-2010
x=IsDate(myDate)
msgbox x 'Output: False
DateDiff Function
Note: through this function, we can day or month wise diffrence only.
IsNumeric
gcreddy.com 3
QTP Training
Example:
Dim val,x
val="100"
x=Isnumeric(val)
msgbox x 'Output: True
val=100
x=Isnumeric(val)
msgbox x 'Output: True
x=Isnumeric(500)
msgbox x 'Output: True
x=Isnumeric("India")
msgbox x 'Output: False
Len Function
Example:
Dim val,x
val="Hyderabad"
x=Len(val)
msgbox x 'Output: 9
val=100
x=Len(val)
msgbox x 'Output: 3
val="Hydera100"
x=Len(val)
msgbox x 'Output: 9
val="hy$@*de"
x=Len(val)
msgbox x 'Output: 7
val="100"
gcreddy.com 4
QTP Training
x=Len(val)
msgbox x 'Output: 3
val=#10-10-2010#
x=Len(val)
msgbox x 'Output: 10
x=Len("Krishna")
msgbox x 'Output: 7
x=Len(Krishna)
msgbox x 'Output: 0
x=Len()
msgbox x 'Output: Error
Left Function
Syntax:
variable=Left(string,Lengh)
Example:
Dim val,x
val="Hyderabad"
x=Left(val,3)
msgbox x ' Output: Hyd
val="9247837478"
x=Left(val,1)
msgbox x ' Output: 9
val="H92yderabad"
x=Left(val,3)
msgbox x ' Output: H92
gcreddy.com 5
QTP Training
x=Left(9247837478,5)
msgbox x ' Output: 92478
val=#10-10-10#
x=Left(val,3)
msgbox x ' Output: 10/
Right Function
Example:
Dim val,x
val="Hyderabad"
x=Right(val,3)
msgbox x ' Output: bad
val="9247837478"
x=Right(val,1)
msgbox x ' Output: 8
val="H92yderabad"
x=Right(val,3)
msgbox x ' Output: bad
x=Right(9247837478,5)
msgbox x ' Output: 37478
val=#10-10-10#
x=Right(val,5)
msgbox x ' Output: /2010
Mid function
Example:
gcreddy.com 6
QTP Training
Dim val,x
val="Hyderabad"
x=Mid(Val,5,3)
msgbox x ' Output: rab
val="Hyderabad"
x=Mid(Val,5)
msgbox x ' Output: rabad
val="9247837478"
x=Mid(val,6,5)
msgbox x ' Output: 37478
val="H92yderabad"
x=Mid(val,1)
msgbox x ' Output: H92yderabad
x=Mid(9247837478,5)
msgbox x ' Output: 837478
val=#10-10-10#
x=Mid(val,5)
msgbox x ' Output: 0/2010
StrReverse
Example:
Dim val,x
val="Hyderabad"
x=StrReverse(val)
msgbox x 'Output dabaredyH
val="001"
x=StrReverse(val)
msgbox x 'Output: 100
val=1002
x=StrReverse(val)
msgbox x 'Output: 2001
gcreddy.com 7
QTP Training
val=#10-10-10#
x=StrReverse(val)
msgbox x 'Output: 0102/01/01
x=StrReverse("Hyderabad")
msgbox x 'Output: dabaredyH
x=StrReverse(100)
msgbox x 'Output: 001
StrComp Function
if
Example:
Dim str1,str2,x
str1="India"
str2="India"
x=StrComp(str1,str2,1)
msgbox x 'Output 0
str1="india"
str2="INDIA"
x=StrComp(str1,str2,1)
msgbox x 'Output 0
str1="India"
str2="Indian"
x=StrComp(str1,str2,1)
msgbox x 'Output -1
str1="Indian"
str2="Ndia"
gcreddy.com 8
QTP Training
x=StrComp(str1,str2,1)
msgbox x 'Output -1
str1="Indian"
str2="India"
x=StrComp(str1,str2,1)
msgbox x 'Output 1
str1=100
str2=100
x=StrComp(str1,str2,1)
msgbox x 'Output 0
str1=100
str2=101
x=StrComp(str1,str2,1)
msgbox x 'Output -1
Lcase function
Dim val,x
val="HYDERABAD"
x=Lcase(val)
msgbox x 'Output hyderabad
val="Hyderabad"
x=Lcase(val)
msgbox x 'Output hyderabad
val="HederabaD"
x=Lcase(val)
msgbox x 'Output hyderabad
val="hyderabad"
x=Lcase(val)
msgbox x 'Output hyderabad
x=Lcase("HYDERABAD")
msgbox x 'Output hyderabad
gcreddy.com 9
QTP Training
Ucase function
Example:
Dim val,x
val="HYDERABAD"
x=Ucase(val)
msgbox x 'Output HYDERABAD
val="Hyderabad"
x=Ucase(val)
msgbox x 'Output HYDERABAD
val="HederabaD"
x=Ucase(val)
msgbox x 'Output HYDERABAD
val="hyderabad"
x=Ucase(val)
msgbox x 'Output HYDERABAD
x=Ucase("HYDERABAD")
msgbox x 'Output HYDERABAD
gcreddy.com 10