Showing posts with label VBScript string functions with examples. Show all posts
Showing posts with label VBScript string functions with examples. Show all posts

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.

VBScript String Functions(1)

VBScript String Functions

1.LCase
2.UCase
3.Left
4.Right
5.Len
6.Mid

LCase Function:Converts a specified string to lowercase.
Syntax:LCase(string)
Ex1:a=LCase("LAKSHMI")
Msgbox a
Output=lakshmi

UCase Function:Converts a specified string to uppercase.
Syntax:UCase(string)
Ex:a=UCase("laxmi")
Msgbox a
Output=LAXMI

Left Function:Returns a specified number of characters from the left side of a string.
Syntax:Left(string,length)
Ex:a=Left("Lakshmi",3)
Msgbox a
Output=Lak

Right Function:Returns a specified number of characters from the right side of a string.
Syntax:Right(string,length)
Ex:a=Right("Lakshmi",3)
Msgbox a
Output=hmi

Len Function:Returns the number of characters in a string.
Syntax:Len(string)
Ex:a=Len("Lakshmi")
Msgbox a
Output=7

Mid Function:Returns a specified number of characters from a string.
Syntax:Mid(string, start[, length])where length is optional.

Ex1:a=Mid("Lakshmi",1)
Msgbox a
Output=Lakshmi

Here starting position of string is 1 and as their is no number specified for length(optional)output is whole string i.e Lakshmi.

Ex2:a=Mid("Lakshmi",4)
Msgbox a
Output=shmi

Starting position is 4 and no length specified result(output)string starts from 4th position of given string to till end of the string i.e shmi

Ex3:a=Mid("Lakshmi",4,3)
Msgbox a
Output=shm

Starting position is 4 and length is 3 result(output)string starts from 4th position of given string and it takes next 2 characters in the string(including 4th position character total becomes 3 characters)and returns the result as shm.

VBScript String Functions(2)

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge

↑