Showing posts with label vbscript functions. Show all posts
Showing posts with label vbscript functions. Show all posts

QTP script to return the number of characters in a string-len function example-qtp script to display the number of characters in a string

Dim a

a=len("qtp")

msgbox " Length of String a is = " & a


Output-Length of String a is = 3



Dim a

a=len("Testing")

msgbox " Length of String a is = " & a


Output-Length of String a is = 7

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.

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge

↑