Beginner's ASP Tutorial: Common ASP built-in functions

Source: Internet
Author: User
Tags expression functions natural logarithm numeric value string square root variable time interval

function, which is a function block encapsulated in the language, to facilitate the user's invocation. For example, "Now" in VBScript is a function that shows the current date and time. As for the specific reason for the display, the language is determined by the kernel, the user only need to understand that "now" is used to show the date time. So, what other functions does VBScript have in our current contact?

1, Date/Time function

These functions include the display of the year, month, day, time, minutes, seconds, week, and so on.

(1) Now function: Returns the current date and time value according to the date and time set by the computer system. Use the method now ();

(2) Date function: Returns only the date value set by the current computer system. How to use: Date ();

(3) Time function: Returns only the value set by the current computer system. How to use: Time ();

(4) The Year function: Returns an Integer that represents an age. How to: Year (date), where the date parameter is any parameter that can represent a date, such as "date ()" to represent an integer that extracts "years" from the date from "date ()".

Alternatively, you can apply this: "Year (#5 20,2006#)" represents an integer value that extracts "years" from May 20, 2006. On the "5 20,2006", can also use the "5-20-2006", "5/20/2006" and other forms of performance, that is, "one day a month" and "one year" combination. Also note that use ' # ' is included to represent date values.

(5) Month function: Returns an integer value between 1 and 12 representing the month of the year. How to use: Month (date). The description of the parameter date is the same as the year function. But pay attention to the correctness of the date, such as "#13 -31-2006#", there is no "13" month, it must be wrong.

(6) Day function: Returns an integer value between 1 and 31 that represents one of the days of the one month. Use Method: Day (date). The description of the parameter date is the same as the year function. Also pay attention to the correctness of the date, such as "#2 -30-2006#" where the "2" month definition of "30" Day is wrong.

(7) Hour function: Returns an integer value between 0 and 23 that represents an hour of the day. How to use: Hour (time). Where the parameter time is any expression that can represent an hour. For example, "Hour (time)" means an integer that extracts "hours" from the period derived from "times ()". Similarly, parameter time can also apply "hour (#11:45:50#)" to indicate that the current number of hours is extracted from 45 "50" Seconds from "11". Of course, the time defined should conform to the specification of the time.

(8) Minute function: Returns an integer value between 0 and 59 that represents a minute in an hour. How to use: Minute (time). The description of the time parameter is the same as the hour function.

(9) Second function: Returns an integer value between 0 and 59 that represents a second in a minute. How to use: Second (time). The description of the time parameter is the same as the hour function.

(Ten) Weekday function: Returns an integer that is one day of the one week. How to use: Weekday (date). The description of the parameter date is the same as the year function. The function returns a value of "1" to "7", representing "Sunday", "Monday" respectively ... "Saturday". For example, when the return value is "4", it means "Wednesday."

(one) WeekdayName function: Returns a string that is specific to the day of the one week. The relative weekday function translates "Day of the Week", using the method: WeekdayName (Weekday). The parameter weekday the value of the day of the week. For example, "WeekdayName (weekday)" means that the current is "Day of the week." Because "date ()" represents the current time, weekday (date ()) represents an integer that is specific to the day of the week.

Of course the WeekdayName function eventually displays the string content also related to the current operating system language, such as Chinese operating system will display the "Monday" of this type of characters, while the English operating system is displayed as "Mon" (Monday shorthand).

In addition, there are some computational functions about time intervals in VBScript:

(1) DateAdd function: Returns the date and time of the specified time interval. You can calculate a new date or time that is many years apart, or a few months apart, or a few hours apart. How to use: DateAdd (interval, number, date).

Where the parameter interval represents the time interval unit that needs to be added. It is expressed in the form of a string, for example, "yyyy" for the year, "Q" For the quarter, "M" for the month, "D" for the number of days, "WW" for the number of weeks, "H" for the number of hours, "n" for minutes, "s" for the number of seconds.

The number of parameters indicates how many time intervals were added. It is expressed in numerical form and can be negative. The parameter date requires the correct format for the date and time.

For example, DATEADD ("D", 100, "2006-5-20") means the date value of the 100 days after May 20, 2006:2006-8-28. Another example is DateAdd ("H",-12, "2005-5-20 10:00:00"), which means the 12-hour date before 10 o'clock in the morning May 20, 2005:2005-5-19 22:00:00.

(2) DateDiff function: Returns the interval between two date and time. You can calculate the age, number of hours, and so on, two dates apart. How to use: DateDiff (INTERVAL,DATE1,DATE2).

The parameter interval and the DATEADD function have the same description of the interval parameter, and the Date1 and Date2 parameters are two date times compared to each other. In addition, when the date1 datetime value is greater than Date2, it is displayed as a negative number.

For example, DateDiff ("yyyy", "1982-7-18", date) indicates how many years has it been since someone's birth. For example, DateDiff ("D", "1982-7-18", "2062-7-18") calculated the number of days after 80 years: 29220.

2, String handler function

In the functional processing of a script, some of the strings are usually decorated with some modification. For example, filter out the sensitive words in the string to meet the requirements of the final display, or, for example, a longer string, you need to extract the first few words characters.

(1) ASC function: Returns the ANSI character code corresponding to the first letter in the string. Use Method: ASC (String). Where string parameters represent strings.

(2) CHR function: Returns the character corresponding to the ANSI character code specified. How to use: Chr (Chrcode). The parameter chrcode is the associated identification number. The functions of the function and the ASC function form the corresponding.

For example, ASC ("A") represents the ANSI character "97" of the lowercase letter "a", and the same Chr (97) denotes "lowercase a". In addition, the CHR (chrcode) parameter chrcode a number from 0 to 31 indicates an ASCII code that is not printable. For example, "Chr (10)" means line breaks, "Chr (13)" means carriage returns, and so on, which is often used in the conversion of input and display formats.

(3) Len function: Returns the number of characters in a string (in bytes). Use method: Len (String). For example, the value of Len ("Love") is 4.

(4) LCase function: Returns the lowercase form of all strings. Use Method: LCase (String). For example, LCase ("webjxcom") is returned as "webjxcom".

(5) UCase function: Returns the uppercase form of all strings. Corresponds to the LCase function form. Similarly, UCase ("WEBJX") is returned as "WEBJX".

(6) Trim function, LTrim function, and RTrim function: Returns the leading and subsequent string content with no spaces, leading without spaces, or followed by no spaces. Like what:

Trim ("1234567") returns to "1234567", leading and trailing without spaces;

LTrim ("1234567") returned to "1234567", leading without spaces;

RTrim ("1234567") returned to "1234567", followed by no space;

This function is often used in registration information, such as ensuring that a space is before or after registering a user name.

(7) Left function: Returns the specified number of characters from the left-hand side of the string. How to use: Left (string,length). For example, left ("Brousce", 5) is returned as "brous", that is, the first five-bit character.

(8) Right function: Returns the specified number of characters from the left of the string. How to use: Right (string,length). For example, right ("Brousce", 4) is returned as "Usce", which is the latter four-bit character.

(9) InStr function: Returns the position where a string appears for the first time in another string. For example now look for the first occurrence of the letter "A" in the string "a110b121c119d1861", You can InStr (my_string, "a110b121c119d1861")

(a) Mid function: Returns a specified number of characters from a string. For example, the current "110" should be from the string "a110b121c119d1861" the 2nd bit to get 3 units of the value: Mid ("a110b121c119d1861", 2, 3)

(one) Replace function: Finds in a string, overrides the specified string. Replace (Strtobesearched,strsearchfor,strreplacewith) where strtobesearched is a string, strSearchFor is the substring being searched, strReplaceWith is a substring to replace. For example, replace (Rscon, "<", "<") means replacing all "<" characters in Rscon with "<"

3, type conversion function

Convert CBool (String) to a Boolean value

CByte (String) to a value of byte type

Ccur (string) converted to currency class value

Cdate (String) to a value of the date type
Convert Cdbl (string) to double values

Convert Cint (string) to integer values

CLNG (String) to a value of a long integer

CSng (String) to a single-precision value

Cstr (Var) conversion to String value

The STR (Var) numeric value is converted to a string

Val (String) string converted to numeric value

4, Operation function

Abs (NMB) returns the absolute value of a number of children

ATN (NMB) returns the tangent of a number

Cos (NMB) returns the dazzle value of an angle

EXP (NMB) returns the secondary value of the natural exponent

INT (NMB) returns the Shaping (rounding) of a number

Fix (NMB) returns the number of plastic (shed) parts

FormatPercent (expression) return percent

Hex (NMB) returns the number of 16 in the data

Log (NMB) returns the natural logarithm

OCT (NMB) returns the number of 8 numbers

Rnd returns a random number that is greater than "0" and less than "1", but previously required randomize to produce a random seed

SGN (NMB) determines the positive and negative number of a number

Sin (NMB) returns the positive-hyun value of the angle

SQR (NMB) returns the two square root of the number

Tan (NMB) returns the tangent 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 an expression contains a numeric value

IsObject (Var) determines whether a variable is an object

TypeName (VAR) returns the data type of a variable

Array (list) returns arrays

Split (LISTSTR) returns a one-dimensional array from a list string

LBound (ARRAYP returns the smallest index of an array

Ubound (array) returns the maximum index of an array

CreateObject (Class) creates an object

GetObject (pathfilename) Get File Object



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.