Recommended: Getting started with ASP: Understand several scripting languages used by ASP programs You cannot see the ASP source code by viewing the source code in the browser. You can only see the results output by the ASP file, and those are just pure HTML. This is because the script has been executed on the server before the result is sent back to the browser. Example: Use
Functions are a function block encapsulated by the language to facilitate user calls. For example, now() is a function in VBScript that can display the current date and time. As for the specific reason why it can be displayed, it is determined by the language kernel. Users only need to understand that now() is used to display date and time. So, do we have any other functions of VBScript we are currently in contact with?
1. Date/time function
These functions include displays of year, month, day, hour, minute, second, week, etc.
(1) Now function: Return the current date and time value based on the date and time set by the computer system. Use method now();
(2) Date function: only returns the date value set by the current computer system. How to use: date();
(3) Time function: only returns the time value set by the current computer system. How to use: time();
(4) Year function: Return an integer representing a certain year. Usage method: year(date), where the date parameter is any parameter that can represent the date. For example, year(date()) means that the integer of the year is extracted from the date obtained by date().
In addition, it can also be used like this: year(#5 20,2006#) means extracting the integer value of the middle age on May 20, 2006. Regarding 5 20,2006, 5-20-2006, 5/20/2006, that is, a combination of a certain month, day and year. Also note that using # is used to include to represent date values.
(5) Month function: Returns an integer value between 1 and 12, representing a month of the year. How to use: month(date). The description about parameter date is the same as the year function. But pay attention to the correctness of the date. For example, #13-31-2006#, there is no December at all, which is definitely wrong.
(6) Day function: Returns an integer value between 1 and 31, indicating a day of a month. How to use: day(date). The description about parameter date is the same as the year function. Also pay attention to the correctness of the date, such as #2-30-2006#, which defines February's 30th day is wrong.
(7) Hour function: Returns an integer value between 0 and 23, indicating an hour of the day. How to use: hour(time). Where the parameter time is any expression that can represent time. For example, hour(time()) means that the integer of the hour is extracted from the time derived from time(). Similarly, the parameter time can also be used in this way to extract the current number of hours from 11:45:50#. Of course, the defined time must comply with the time specifications.
(8) Minute function: Returns an integer value between 0 and 59, representing a certain minute in an hour. How to use: minute(time). The description of time parameter is the same as the hour function.
(9) Second function: Returns an integer value between 0 and 59, representing a certain second in a minute. How to use: second(time). The description of time parameter is the same as the hour function.
(10) Weekday function: Returns the integer of a day of the week. How to use: weekday(date). The description about parameter date is the same as the year function. The return value of this function is 1 to 7, representing Sunday, Monday, and Saturday respectively. For example, when the return value is 4, it means Wednesday.
(11) WeekDayName function: Returns the string of a specific day of the week. Compared with the weekday function, it is translated into the day of the week. The usage method is: weekdayname(weekday). The parameter weekday is the value of a specific day of the week. For example, weekdayname(weekday(date())) means that the current day of the week. Because date() represents the current time, while weekday(date()) represents the integer of a specific day of the week.
Of course, the string content of the final display of the weekdayname function is also related to the current operating system language system. For example, the Chinese operating system will display Chinese characters such as Monday, while the English operating system will display Mon (Monday abbreviation).
In addition, there are some calculation functions for time intervals in VBScript:
(1) DateAdd function: Returns the date and time of the specified time interval. You can calculate a new date and time that is separated by many years, months, or hours, etc. How to use: dateadd(interval, number, date).
The parameter interval represents the time interval unit that needs to be added. It is expressed in the form of a string, such as yyyy represents year, q represents quarter, m represents month, d represents days, ww represents weeks, h represents hours, n represents minutes, and s represents seconds.
The parameter number indicates the number of time intervals added. It is expressed in the form of a numerical value and can be a negative value. The parameter date requires that it is the correct format of date and time.
For example, dateadd(d,100, 2006-5-20) represents the date value of 100 days after May 20, 2006: 2006-8-28. For example, dateadd(h,-12,2005-5-20 10:00:00) represents the date time of the 12 hours before 10:00 am on May 20, 2005: 22:00:00.
(2) DateDiff function: Returns the interval between two dates and times. The years, hours, etc. that are separated by two dates can be calculated. How to use: datediff(interval,date1,date2).
The interval parameters in the parameter interval and dateadd functions are the same description, and the date1 and date2 parameters are two dates and times that are compared with each other. In addition, when the date-time value of date1 is greater than date2, it will be displayed as a negative value.
For example, DateDiff(yyyy, 1982-7-18, date) means how many years it has been since someone was born. For example, DateDiff(d, 1982-7-18, 2062-7-18) calculates how many days have passed in 80 years: 29220.
2. String processing function
In the functional processing of scripts, some strings are usually required to be modified. For example, filter out sensitive words in strings to meet the final display requirements; for example, when a longer string needs to be extracted from the beginning of a few characters.
(1) Asc function: Returns the ANSI character code corresponding to the first letter in the string. How to use: asc(string). where string parameter represents a string.
(2) Chr function: Returns the character corresponding to the ANSI character code specified. How to use: chr(chrcode). The parameter chrcode is the relevant identification number. The function of this function corresponds to the asc function.
For example: asc(a) represents the ANSI character 97 of the lowercase letter a; chr(97) represents the lowercase letter a. In addition, when the chrcode value in chr(chrcode) has a number with a value of 0 to 31, it indicates an ASCII code that cannot be printed. For example, chr(10) represents line breaks, chr(13) represents carriage return, etc., which are often used in the conversion of input and display formats.
(3) Len function: Returns the number of characters (bytes) in the string. How to use: len(string). For example, the value of len(love) is 4.
(4) LCase function: Returns the lowercase form of all strings. How to use: lcase(string). For example, lcase(WEBJXCOM) returns to CuoXIncom.
(5) UCase function: Returns the uppercase form of all strings. Correspond to the lcase function. Similarly, ucase(CuoXIn) returns to WEBJX.
(6) Trim function, LTrim function and RTrim function: Return the leading and subsequent string content without spaces, leading and subsequent without spaces, or subsequent without spaces, respectively. for example:
trim(1234567) returns to 1234567, with no spaces in the leading and subsequent lines;
ltrim(1234567) returns to 1234567, leading without spaces;
rtrim(1234567) returns to 1234567, without spaces in the future;
This function is often used in registration information, such as ensuring spaces before or after the registered username.
(7) Left function: Returns the specified number of characters calculated from the left side of the string. How to use: left(string,length). For example, left(brousce,5) returns to brous, that is, the first five characters.
(8) Right function: Returns the specified number of characters calculated from the left side of the string. How to use: right(string, length). For example, right(brousce,4) returns to usce, that is, the last four characters.
(9) instr function: Returns the position where a certain string first appears in another string. For example, now look for the first occurrence of letter A in the string A110B121C119D1861, then you can instr(my_string,A110B121C119D1861)
(10) Mid function: Returns the specified number of characters from the string. For example, the current 110 should obtain 3 units of values from the second bit of the string A110B121C119D1861: mid(A110B121C119D1861,2,3)
(11) Replace function: find and replace the specified string in the string. replace(strtobesearched,strsearchfor,strreplacewith) where strtobesearched is a string, strsearchfor is the substring being looked up, and strreplacewith is the substring used to replace. For example, replace(rscon,<,<) means replacing all < characters in rscon with<
3. Type conversion function
Cbool(string) converts to boolean
Cbyte(string) Convert to a value of byte type
Ccur(string) Convert to currency value
Cdate(string) Convert to a value of the day-old type
Cdbl(string) converts to double precision value
Cint(string) Convert to integer value
Clng(string) converts to long integer value
Csng(string) converts to single-precision value
Cstr(var) converts to string value
Str(var) value converted to string
Val(string) string to numeric value
4. Operation function
Abs(nmb) returns the absolute value of the number
Atn(nmb) Returns the arc tangent of a number
Cos(nmb) Returns the Yuxuan value of an angle
Exp(nmb) Returns the power value of the natural index
Int(nmb) Returns the shaping (carry) part of the number
Fix(nmb) Returns the skeleton (discarded) part of the number
Formatpercent(expression) Returns percentage
Hex(nmb) Returns the hex number of data
Log(nmb) Returns natural logarithm
Oct(nmb) Returns the angular number of the number
Rnd returns a random number greater than 0 and less than 1, but the randomize declaration is required to generate a random seed.
Sgn(nmb) determines the positive and negative signs of a number
Sin(nmb) Returns the Zhenghyun value of the angle
Sqr(nmb) returns the quadratic root of the number
Tan(nmb) Returns the tangent value of a number
5. Other functions
IsArray(var) determines whether a variable is an array
IsDate(var) determines whether a variable is a date
IsNull(var) determines whether a variable is empty
IsNumeric(var) determines whether the expression contains numeric values
IsObject(var) determines whether a variable is an object
TypeName(var) Returns the data type of the variable
Array(list) Returns an array
Split(liststr) Returns a one-dimensional array from a list string
LBound(arrayP Returns the minimum index of the array
Ubound(array) Returns the maximum index of the array
CreateObject(class) Create an object
GetObject(pathfilename) Get file object
Share: Use ASP programming to achieve rapid search of network content One day I had a sudden idea that if I could immediately call up the information I needed to read every time I went to a website, wouldn't it be very wonderful? Next I want to think about this issue more deeply, sit in a chair and grab a pencil, but don’t know what I’m writing. In this way, I still have