STRING FUNCTIONS:
- InStr-returns the position of the first occurrence of one
string within another.
Syntax: InStr([start,]string1,string2[,compare])
Start-Optional. Specifies the starting position for each search.
The search begins at the first character position (1) by default. This
parameter is required if compare is specified
String1-Required. The string to be searched
String2-Required. The string expression to search for
Compare-Optional. Specifies the
string comparison to use. Default is 0
Can have one of the
following values:
- 0 = vbBinaryCompare - Perform a binary comparison
- 1 = vbTextCompare - Perform a textual comparison
Example: txt="Introduction to vbscript!"
response.write(InStr(txt,"vbscript"))
response.write(InStr(txt,"vbscript"))
Output:17
- InStrRev-returns the position of the first occurrence of one string within another. The search begins from the end of string, but the position returned counts from the beginning of the string.
Syntax: InStrRev(string1,string2[,start[,compare]])
String1-Required. The string to be searched
String2-Required. The string expression to search for
Start-Optional. Specifies the starting position for each search. The search
begins at the last character position by default (-1)
Compare-Optional. Specifies the string comparison to use. Default
is 0
Can have one of the
following values:
- 0 = vbBinaryCompare - Perform a binary comparison
- 1 = vbTextCompare - Perform a textual comparison
Example: txt="Introduction
to vbscript!"
response.write(InStrRev(txt,"vbscript"))
response.write(InStrRev(txt,"vbscript"))
Output:8
- Lcase-converts a specified string to lowercase.
Syntax: LCase(string)
Example: txt="INTRODUCTION TO VBSCRIPT!"
response.write(LCase(txt))
response.write(LCase(txt))
Output: introduction to vbscript
- Left: returns a specified number of characters from the
left side of a string.
Syntax: Left(string,length)
Example: txt="INTRODUCTION TO VBSCRIPT"
response.write(Left(txt,15))
response.write(Left(txt,15))
Output:”INTRODUCTION TO”
- Len- returns the number of characters in a string.
Syntax: Len(string)
Example: txt="INTRODUCTION
TO VBSCRIPT"
response.write(Len(txt))
Output:24
- LTrim- removes spaces on the left side of a string.
Syntax: LTrim(string)
Example: fname=" Jaya"
response.write("Hello" & LTrim(fname) & "and welcome.")
response.write("Hello" & LTrim(fname) & "and welcome.")
Output: HelloJaya and welcome.
- RTrim- removes spaces on the right side of a string.
Syntax: RTrim(string)
Example: fname=" Jaya"
response.write("Hello" & LTrim(fname) & "and welcome.")
response.write("Hello" & LTrim(fname) & "and welcome.")
Output: Hello Jayaand welcome.
- Trim- removes
spaces on both sides of a string.
Syntax: Trim(string)
Example: fname=" priya"
response.write("Hello" & Trim(fname) & "and welcome.")
response.write("Hello" & Trim(fname) & "and welcome.")
Output: Hellopriyaand welcome
- Mid- returns a specified number of
characters from a string.
Syntax: Mid(string,start[,length])
String- Required. The string expression from which characters are
returned
Start- Required. Specifies
the starting position. If set to greater than the number of characters in
string, it returns an empty string ("")
Length-optional. The number of characters to return
Example: txt="Introduction to vbscript!"
response.write(Mid(txt,1,1))
response.write(Mid(txt,1,1))
Output:I
- Replace- replaces a specified part of a
string with another string a specified number of times.
Syntax Replace(string,find,replacewith[,start[,count[,compare]]])
String- Required. The string to be searched
Find- Required. The part of
the string that will be replaced
Replacewith- Required. The replacement substring
Start- Optional. Specifies
the start position. Default is 1. All characters before the start position will
be removed.
Count-Optional. Specifies the number of substitutions to perform.
Default value is -1, which means make all possible substitutions
Default value is -1, which means make all possible substitutions
Compare- Optional. Specifies the string
comparison to use. Default is C
Can have one of the following values:
- 0 =
vbBinaryCompare - Perform a binary comparison
- 1 = vbTextCompare - Perform a textual comparison
Example: txt="This is a beautiful day!"
response.write(Replace(txt,"beautiful","fantastic"))
response.write(Replace(txt,"beautiful","fantastic"))
Output: This is a fantastic day!
- Right- returns
a specified number of characters from the right side of a string.
Syntax: Right(string,length)
Example- txt="This
is a beautiful day!"
response.write(Right(txt,10))
response.write(Right(txt,10))
Output: tiful
day!
- Space- returns
a string that consists of a specified number of spaces.
Syntax: Space(number)
Example: Dim txt
txt=Space(10)
response.write(txt)
txt=Space(10)
response.write(txt)
Output: " "
- StrComp- compares two strings and returns a value that
represents the result of the comparison.
Syntax:
StrComp(string1,string2[,compare])
String1- Required. A string expression
String2- Required. A string expression
Compare- Optional. Specifies the string comparison to use. Default
is 0
Can have one of the following values:
- 0 = vbBinaryCompare - Perform a binary comparison
- 1 = vbTextCompare - Perform a textual comparison
Example-
response.write(StrComp("VBScript","VBScript"))
Output-0
- String- returns
a string that contains a repeating character of a specified length.
Syntax:
String(number,character)
Number- Required. The length of the returned string
Character- Required. The character that will be repeated
Example: response.write(String(10,"#"))
Output: ##########
- StrReverse- reverses a string.
Syntax:
StrReverse(string)
Example: Dim txt
txt="This is a beautiful day!"
response.write(StrReverse(txt))
txt="This is a beautiful day!"
response.write(StrReverse(txt))
Output: !yad lufituaeb a si sihT
- UCase- converts
a specified string to uppercase.
Syntax:
UCase(string)
Example: txt="This
is a beautiful day!"
response.write(UCase(txt))
response.write(UCase(txt))
Output: THIS
IS A BEAUTIFUL DAY!
No comments:
Post a Comment