ASP VBScript Function Cheat Sheet - ASP Tutorial
VBScript functions
Function description
example
Abs (numeric) absolute value. The absolute value of a number is its positive value. The absolute value of the empty string (null) is also the empty string. Uninitialized variable, which is absolutely 0 Example: ABS(-2000)
Result: 2000Array (comma-separated array elements) The Array function returns the value of the array element. example:
A=Array(1,2,3)
B=A(2)
Result: 2
Explanation: Variable B is the value of the second element of array A. Asc (string) converts the first letter of the string into ANSI (American National Standard Notation) character code. Example: Asc ("Internet")
Result: 73
Description: Display the ANSI character code of the first letter I. CBool (expression) is converted into a Boolean logical value variable type (True or False) Example: CBool (1+2)
Result: True CDate (date expression) is converted into date variable type. You can first use the IsDate function to determine whether it can be converted into a date. Example: CDate (now( )+2)
Result: 2000/5/28 10:30:59 CDbl (expression) is converted into DOUBLE variable type. Chr (ANSI character code) converts ASCII character codes into characters. Example: Chr(72)
Result: H CInt (expression) is converted to integer variable type. Example: CInt (3.12)
Result: 3 CLng (expression) is converted into LONG variable type. CSng (expression) is converted into SINGLE variable type. CStr (expression) is converted into a string variable type. Date() returns the system date. Example: Date
Result: 2000/5/13DateAdd (I, N, D) adds a date to the date after a period. I: Set the unit of a period added to a date (Date). For example, interval=d means that the unit of N is day. The setting value of I is as follows:
yyyy Year
q Quarter
m Month Month
d Day
w Weekday week
h Hour
n Minutes
s Second seconds
N: Numerical expression, setting a period added to a date, which can be a positive value or a negative value. A positive value means adding (the result is the date after > date), and a negative value means subtracting (the result is > the date before date). date).
D: The date to be added or subtracted. Example: DateAdd ( m , 1 , 31-Jan-98)
Result: 28-Feb-98
Explanation: Add one month to the date 31-Jan-98, the result is 28-Feb-98 instead of 31-Fe-98.
Example: DateAdd ( d , 20 , 30-Jan-99)
Result: 1999/2/9
Description: Add a date 30-Jan-99 to the date 20 days later. DateDiff (I , D1 , D2[,FW[,FY]]) calculates the period between two dates.
I: Set the unit for calculating the period between two dates. For example, >I=m means that the calculation unit is month. >The setting value of I is as follows:
yyyy > Year
q Quarter
m Month Month
d Day
w Weekday week
h Hour
m Minutes
s Second seconds
D1, D2: Two date expressions for calculating the period. If >date1 is earlier, the result of the period between the two dates will be positive; if >date2 is earlier, the result will be negative.
FW: Set the first day of the week as the day of the week. If not set, it will be Sunday. >The setting values of FW are as follows:
0 Use the setting value of >API.
1 sunday
2 Monday
3 Tuesday
4 wednesday
Thursday 5
6 Friday
7 saturday
FY: Set the first week of the year. If not set, it means the week of January 1st is the first week of the year. >The setting values of FY are as follows:
0 Use the setting value of >API.
1 The week of January 1st is the first week of the year
2 The first week containing at least four days shall be the first week of the year
3 The first week including seven days is the first week of the year. Example: DateDiff (d,25-Mar-99,30-Jun-99)
Result: 97
Description: Displays a period of 97 days between two dates. DatePart (I,D,[,FW[,FY]]) returns the part of a date.
>I: Set the part to be returned. For example, >I=d means that the returned part is day. >The setting value of I is as follows:
yyyy Year
q Quarter
m Month Month
d Day
w Weekday week
h Hour
m Minutes
s Second seconds
D: The date to be calculated.
>FW: Set the day of the week as the first day of the week. If not set, it will be Sunday. >The setting values of FW are as follows:
0 Use the setting value of >API.
1 sunday
2 Monday>3 Tuesday
4 wednesday
Thursday 5
6 Friday
7 saturday
FY: Set the first week of the year. If not set, it means the week of January 1st is the first week of the year. >The setting values of FY are as follows:
0 Use the setting value of >API.
1 The week of January 1st is the first week of the year
2 The first week containing at least four days shall be the first week of the year
3 Example of the first week of the year including the first week of seven days: DatePart (m,25-Mar-99)
Result: 3
Description: Display the month part of a date returned. Dateserial (year,month,day) converts (year,month,day) into date variable type. Example: DateSerial (99,10,1)
Result: 1999/10/1DateValue (date string or expression) is converted into date variable type, and the date ranges from January 1,100 to December 31,9999. The format is month, day, and year or month/day/year. For example: December 30,1999, Dec 30,1999, 12/30/1999, 12/30/99 Example: DateValue (January 1,2002)
Result: 2002/1/1Day (date string or expression) returns the "day" part of the date. Example: Day(12/1/1999)
Result: 1Fix(expression) converts the string into an integer numeric type. Same as the Int function. If it is null, return null.
The difference between Int (number) and Fix(number) is negative numbers. Such as Int (-5.6)=-6, Fix(-5.6)=-5. Example: Fix(5.6)
Result: 5Hex(expression) returns the hexadecimal value of the number. If the expression is null, Hex(expression)=null, if the expression=Empty, Hex(expression)=0. Hexadecimal carry can be expressed by adding "&H". For example, 16 carry &H10 represents 16 in decimal. Example: Hex(30)
Result: 1EHour (a string or expression of time) returns the "hour" portion of the time. Example: Hour(12:30:54)
Result: 12InStr ([start,]string1,string2[,compare]) Compares one string with another from left to right and returns the first identical position.
start is the number of characters to start comparison from. If start is omitted, comparison will start from the first character. string1 is the string expression to be found, string2 is the string expression to be compared, compare is the comparison method, compare= 0 represents the binary comparison method, compare=1 represents the text comparison method, if compare is omitted, the default binary comparison method is used. Example: InStr(abc123def123,12)
Result: 4InstrRev ([start,]string1,string2[,compare]) compares one string with another from right to left, and returns the first identical position.
start is the number of characters to start comparison from. If start is omitted, comparison will start from the first character. string1 is the string expression to be found, string2 is the string expression to be compared, compare is the comparison method, compare= 0 represents the binary comparison method, compare=1 represents the text comparison method, if compare is omitted, the default binary comparison method is used. Example: InstrRev (abc123def123,12)
Result: 10Int (expression) returns the integer part of a value. Same as Fix function. Example: Int (5.6)
Result: 5IsArray (variable) tests whether the variable is (True) or not (False) an array. Example: IsArray(3)
Result: False
Description: Not an array. Whether IsDate (an expression of date or string) can be converted to a date. Dates range from January 1,100 AD to December 31,9999 AD. Example: IsDate (December 31,1999)
Result: True
Description: Can be converted into date. IsEmpty (variable) tests whether the variable is (True) or not (False) has been initialized. Example: IsEmpty (a)
Result: TrueIsNull (variable) tests whether the variable is (True) or not (False) not valid data. Example: IsNull()
Result: False
Description: It is valid data. IsNumeric (expression) is (True) or not (False) a number. Example: IsNumeric (abc123)
Result: False
Note: Not a number. LCase (string expression) top converts strings to lowercase. Convert uppercase letters to lowercase. The rest of the string is unchanged. Example: LCase (ABC123)
Result: abc123Left(string expression, length) takes the characters on the left side of the string. length is a word. The Len function tells you the length of a string. Example: Left(ABC123,3)
Result: ABCLen (string expression variable) obtains the length of the string. Example: Len(ABC123)
Result: 6LTrim (string expression) removes whitespace on the left side of the string. RTrim removes the blank characters on the right side of the string, and the Trim function removes the blank characters on the left and right sides of the string. Example: LTrim (456+ abc )
Result: 456abc123Mid(string expression,start[,length]) takes several words in the string. start is the number of characters to start from, length is the number of characters to be taken from, if length is omitted, it is taken from start to the rightmost bottom. The length of the string can be known by the Len function. Example: Mid(abc123,2,3)
Result: c12Minute (a date string or expression) returns the "minute" portion of the time. Example: Minute(12:30:54)
Result: 30Month (a string or expression of date) returns the "month" part of the date. Example: Month(12/1/2001)
Result: 12MonthName(month[,abbreviate]) returns the name of the month.
month: The number 1~12 of the month name to be returned. For example, 1 represents January and 7 represents July.
abbreviate: Yes (True) No (False) is an abbreviation, such as March, the abbreviation is Mar. The default value is False. Chinese month names have no abbreviations. Example: MonthName (7)
Result: JulyNow() returns the system date and time. Example: Now()
Result: 2001/12/30 10:35:59 AMOct() returns the octal value of the value. The octal digit can be expressed by adding "&O". For example, the octal digit &O10 represents 8 in decimal. Example: Oct(10)
Result: 12Replace(string expression,findnreplacewith[,start[,count[,compare]]]) replaces part of the words with a string. Search for the original string to be replaced (find). If found, it will be replaced with a new string (replacewith).
find: The original string to be found and replaced.
replacewith: the replaced word.
start: From which character to start searching for replacement. If not set, search will start from the first character.
count: the number of substitutions. If not set, all found string replacement strings will be replaced.
compare: Find the comparison method, compare=0 means binary comparison method, compare=1 means text comparison method, compare =2 means it depends on the data type of comparison, if compare is omitted, it is the default binary comparison method. Example: Replace(ABCD123ABC,AB,ab)
Result: abCD123abCRight(string expression, length) takes several words on the right side of the string, and length is the number of words taken. The Len function tells you the length of a string. Example: Right(ABC123,3)
Result: 123Rnd [(number)] Random random value between 0 and 1. number is any valid numeric expression. If number is less than 0, it means that the same random value will be obtained every time. When number is greater than 0 or not provided, it means to get the next random value in sequence. >number=0 means to get the most recently generated random value. In order to avoid getting the same random random number sequence, you can add Randomize before the Rnd function. Example: Rnd
Result: 0.498498Round(numeric expression[,D]) is rounded.
D: The decimal place to which the value is rounded. If omitted, the value is rounded to an integer. Example: Round(30635,1)
Result: 3.6RTrim (string expression) removes whitespace on the right side of the string. LTrim removes the blank characters on the left side of the string, and the Trim function removes the blank characters on the left and right sides of the string. Example: RTrim (abc123)+456
Result: abc123456Second (string or expression of time) returns the "second" part of the time. Example: Second(12:30:54)
Result: 54Space (number of repetitions) gets the same blank string repeated. Example: A+Space (5)+B
Result: AB
Instructions: Add five blank words between A and B. String (number of repetitions, word to be repeated) gets the same string repeated. Example: String(5,71)
Result: GGGGGStrReverse (String(10,71)) reverses the order of a string. Example: StrReverse(ABC)
Result: CBATime() returns the system time. Example: Time
Result: 10:35:59 PMTimeSerial (hour, minute, second) converts the specified (hour, minute, second) into a time variable type. Example: TimeSerial (10,31,59)
Result: 10:31:59TimeValue (date string or expression) is converted into time variable type. A string or expression of date from 0:00:00(12:00:00 AM) to 23:59:59(11:59:59 PM). Example: TimeValue (11:59:59)
Result: 11:59:59Trim (string expression) removes the blank characters on the left and right sides of the string. Example: Trim(abc123)
Result: abc123UCase() converts the string to uppercase. Convert lowercase letters to uppercase, leaving the rest of the string unchanged. Example: UCase (abc123)
Result: ABC123VarType (variable) returns a variable type. Same as the TypeName function, VarType returns the code of the variable type and TypeName returns the name of the variable type. Example: VarType (I love you!)
Result: 8Weekday(date expression,[FW]) returns the day of the week number.
FW: Set the day of the week when the first day of the week is. If omitted, Table 1 (Sunday).
Firstdayfweek setting values are: 1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday). Example: Weekday(1/1/2000)
Result: 7WeekDayName (W,A,FW) returns the name of the day of the week.
W: Yes (True) or No (False) is the abbreviation. For example, March is abbreviated as Mar. Default is False. The Chinese day of the week names have no abbreviations.
FW: Set the day of the week when the first day of the week is. If Table 1 (Sunday) is omitted. Set the name of the day of the week to be returned as the day of the week.
A: 1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday). Example: WeekDayName (1/1/2000)
Result: Saturday Year() returns the "year" part of the date. Example: Year(12/1/2000)
Result: 2000