VBScript String Functions(2)

VBScript String Functions(1)

1.LTrim
2.RTrim
3.Trim
4.Replace
5.StrReverse
6.Space

LTrim Function:Removes spaces on the left side of a string.
Syntax:LTrim(string)
Ex1:a=LTrim(" LAKSHMI ")
Msgbox a
Output=LAKSHMI .

RTrim Function:Removes spaces on the right side of a string.
Syntax:RTrim(string)
Ex1:a=RTrim(" LAKSHMI ")
Msgbox a
Output= LAKSHMI.

Trim Function:Removes spaces on both the left and the right side of a string.
Syntax:Trim(string)
Ex1:a=Trim(" LAKSHMI ")
Msgbox a
Output=LAKSHMI.

Replace Function:Replaces a specified part of a string with another string a specified number of times.
Syntax:Replace(expression, find, replacewith[, start[, count[, compare]]])
where start,count,compare are optional.

expression:String expression containing substring to replace.
find:Substring being searched for.
replacewith:Replacement substring.
start(Optional):Position within expression where substring search is to begin. If omitted,1 is assumed.
count(Optional):Number of substring substitutions to perform. If omitted, the default value is -1, which means make all possible substitutions.
compare(Optional):Numeric value indicating the kind of comparison to use when evaluating substrings.If omitted,the default value is 0, which means perform a binary comparison.

Ex1:a= Replace("abacadaeaf","a","x")
Msgbox a
Output=xbxcxdxexf.

Ex2:a=Replace("abacadaeaf","a","x",1,3)
Msgbox a
Output=xbxcxdaeaf.

As we are giving values for start and count parameters(optional)in above example only first 3 a's are replaced by x.

StrReverse Function:Reverses a string.
Syntax:StrReverse(string)
Ex1:a=StrReverse("Lakshmi")
Msgbox a
Output=imhskaL.

Space Function:Creates a string with the specified number of spaces.
Syntax:Space(number)
Ex1:a="Welcome"&space(5)&"All"
Msgbox a
Output=Welcome All.

2 comments:

Syam.. said...

QTP VBScript - Are you sure 1+1=2?

n1 = InputBox("Enter first number")
n2 = InputBox("Enter second number")
n1increased = n1 + 1

If n1increased = n2 Then
MsgBox n1 & " + 1 equals " & n2
Else
MsgBox n1 & " + 1 doesn't equal " & n2
End If

Anonymous said...

hi,

this is gracy. i have a doubt in working with round function of qtp. when it is used for 2 decimal places of the values 16.955, 17.955, 18.955, 19.955. It should give the result as 16.96, 17.96, 18.96, 19.96 but it is giving the result as 16.95, 17.95, 18.95 and 19.95. could you give me any solution for this. or the reason why it is taking like this?

thanks,
gracy

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge