VBScript Programs PART - II
'****************************************************
'11 Find how many alpha characters present in a string.
Dim oStr
Dim oLength
Dim oChar
Dim iLoop
oStr="su1h2kar"
oLength=len(oStr)
oAlphacounter=0
For iLoop=1 to oLength
If not isnumeric (mid(oStr,iLoop,1)) then
oAlphacounter=oAlphacounter+1
End if
Next
print oAlphacounter
'****************************************************
'****************************************************
'12 Find occurrences of a specific character in a string
Dim oStr
Dim oArray
Dim ochr
oStr="sudhakar"
ochr="a"
oArray=split(oStr,ochr)
print ubound(oArray)
'****************************************************
'****************************************************
'13 Replace space with tab in between the words of a string.
Dim oStr
Dim fStr
oStr="Quick Test Professional"
fStr=replace(oStr," ",vbtab)
print fStr
'****************************************************
'****************************************************
'14 Write a program to return ASCII value of a given character
Dim ochr
Dim aVal
ochr="A"
aVal=asc(ochr)
print aVal
'****************************************************
'****************************************************
'15 Write a program to return character corresponding to the given ASCII value
Dim ochr
Dim aVal
aVal=65
oChr=chr(aVal)
print oChr
'****************************************************
'****************************************************
'16 Convert string to Upper Case
Dim oStr
Dim uStr
oStr="QuickTest Professional"
uStr=ucase(oStr)
print uStr
'****************************************************
'****************************************************
'17 Convert string to lower case
Dim oStr
Dim lStr
oStr="QuickTest Professional"
lStr=lcase(oStr)
print lStr
'****************************************************
'****************************************************
'18 Write a program to Replace a word in a string with another word
Dim oStr
Dim oWord1
Dim oWord2
Dim fStr
oStr="Mercury Quick Test Professional"
oWord1="Mercury"
oWord2="HP"
fStr=replace(oStr,oWord1,oWord2)
print fStr
'****************************************************
'****************************************************
'19 Check whether the string is a POLYNDROM
Dim oStr
oStr="bob"
fStr=StrReverse(oStr)
If oStr=fStr Then
Print "The Given String "&oStr&" is a Palindrome"
else
Print "The Given String "&oStr&" is not a Palindrome"
End If
'****************************************************
'****************************************************
'20 Verify whether given two strings are equal
Dim oStr1
Dim ostr2
oStr1="qtp"
oStr2="qtp"
If oStr1=oStr2 Then
Print "The Given Strings are Equal"
else
Print "The Given Strings are not Equal"
End If
'****************************************************
No comments:
Post a Comment