27 function sets commonly used in ASP. netweb Programming
1. datetime numeric type
Reference content is as follows: System. datetime currenttime = new system. datetime (); 1.1 take the current year, month, day, hour, minute, second currenttime = system. datetime. now; 1.2 take the current year int year = currenttime. Year; 1.3 The current month int month = currenttime. month; 1.4 Use the int day of the current day = currenttime. Day; 1.5 when the current int value is used: = currenttime. hour; 1.6 take the current minute Int = currenttime. minute; 1.7 take the current second int second = currenttime. Second; 1.8 take the current millisecond int millisecond = currenttime. millisecond; (The variable can be in Chinese) |
[Chinese webmaster site]
2. int32.parse (variable) int32.parse ("constant ")
Webmaster Station
Reference content is as follows: Convert string type to 32-digit chinaz |
Webmaster Station
3. Variable. tostring ()[Chinese webmaster site]
Reference content is as follows: Convert string to string 12345. tostring ("N"); // generate 12,345.00 12345. tostring ("C"); // generate $12,345.00 12345. tostring ("e"); // generate 1.234500e + 004 12345. tostring ("F4"); // generate 12345.0000 12345. tostring ("X"); // generate 3039 (hexadecimal) 12345. tostring ("p"); // generate 1,234,500.00%Webmaster Station |
Chinaz
4. Variable. Length numeric type
[Chinese webmaster site]
Reference content is as follows: String Length: For example, string STR = "China "; Int Len = Str. length; // Len is a custom variable, and STR is the variable name of the string to be tested. [Chinese webmaster site] |
[Chinese webmaster site]
5. system. Text. encoding. Default. getbytes (variable)Webmaster Station
Reference content is as follows: Convert character code to bit code For example, byte [] bytstr = system. Text. encoding. Default. getbytes (STR ); Then we can get the bit length: Len = bytstr. length;Webmaster Station |
Webmaster Station
6. system. Text. stringbuilder ("") [Chinese webmaster site]
Reference content is as follows: String addition, (is the same as the + number ?) For example, system. Text. stringbuilder sb = new system. Text. stringbuilder (""); SB. append ("China "); SB. append ("people "); SB. append ("Republic "); |
Webmaster Station
7. Variable. substring (parameter 1, parameter 2 );
[Chinese webmaster site]
Reference content is as follows: Part of the string to be truncated. Parameter 1 is the start number of digits on the left, and parameter 2 is the number of digits to be truncated. For example, string S1 = Str. substring );Webmaster Station |
[Chinese webmaster site]
8. String user_ip = request. servervariables ["remote_addr"]. tostring ();Chinaz
Reference content is as follows: Obtain the IP address of a remote userWebmaster Station |
[Chinese webmaster site]
9. Obtain the real IP address of the remote user through the proxy server:
[Chinese webmaster site]
Webmaster Station
Reference content is as follows: If (request. servervariables ["http_via"]! = NULL ){ String user_ip = request. servervariables ["http_x_forwarded_for"]. tostring (); } Else { String user_ip = request. servervariables ["remote_addr"]. tostring (); } |
Chinaz
10. session ["variable"];
Webmaster Station
Reference content is as follows: Access session value; For example, assign a value: session ["username"] = ""; Value: Object objname = session ["username"]; String strname = objname. tostring (); Clear: Session. removeall (); |
[Chinese webmaster site]
11. String STR = request. querystring ["variable"];Chinaz
Reference content is as follows: Use hyperlinks to send variables. For example, create a hyperlink on any page: Click On the edit. ASPX page, set the value to string STR = request. querystring ["fdid"]; Chinaz |
Chinaz
12. Doc object. createelement ("new node name ");
[Chinese webmaster site]
Reference content is as follows: Create a new node for the XML document Webmaster Station |
[Chinese webmaster site]
13. parent node. appendchild (child node );
[Chinese webmaster site]
Reference content is as follows: Add the new child node to the XML document parent node.Webmaster Station |
14. parent node. removechild (node );
Chinaz
Reference content is as follows: Delete a node[Chinese webmaster site] |
15. Response
[Chinese webmaster site]
Reference content is as follows: Response. Write ("string "); Response. Write (variable ); Output to the page. Response. Redirect ("url address "); Jump to the page specified by the URL. |
16. Char. iswhitespce (STRING variable, digits) -- Logical chinaz
Reference content is as follows: Check whether the specified position contains null characters; For example: String STR = "Chinese people "; Response. Write (char. iswhitespace (STR, 2); // The result is true. The first character is 0, and the second is the third character.[Chinese webmaster site] |
17. Char. ispunctuation ('characters') -- Logical typeChinaz
Reference content is as follows: Check whether a character is a punctuation mark. For example: Response. Write (char. ispunctuation ('A'); // return: false [Chinese webmaster site] |
18. (INT) 'characters' webmaster Station
Reference content is as follows: Convert characters into numbers and queryCodePoint, note that it is single quotes. For example: Response. Write (INT) 'in'); // The code with the result of a Chinese character: 20013 [Chinese webmaster site] |
19. (char) Code
Webmaster Station
Reference content is as follows: Convert the number into characters and check the characters represented by the Code. For example: Response. Write (char) 22269); // return the word "country. |
Webmaster Station
20. Trim ()
Webmaster Station
Reference content is as follows: Clear leading and trailing Spaces Webmaster Station |
21. string variable. Replace ("substring", "Replace ")Chinaz
Reference content is as follows: String replacement For example: String STR = "China "; STR = Str. Replace ("country", "Central"); // Replace the Chinese character with the central character Response. Write (STR); // The output result is "Central" Another example is: (this is very practical) String STR = "This Is A <SCRIPT> script "; STR = Str. replace ("<", "<font> </font> "); // Replace the left angle brackets with <font> and </font> (or replace them with <, but it is estimated that after saving the XML, it will be restored again) Response. Write (STR); // display as: "This is a <SCRIPT> script" If not replaced, <SCRIPT> is not displayed. If it is a script, it runs. If it is replaced, the script does not run. [Chinese webmaster site]The value of this Code is that you can invalidate and display all HTML tags in a text file to protect your interactive websites. Specific implementation: Add the following code to your form submission button script: String strsubmit = label1.text; // label1 is the Control ID for you to submit data. Strsubmit = strsubmit. Replace ("<", "<font> </font> "); Then save or output strsubmit. This method can also be used to easily implement the UBB code. Chinaz |
22. Math. Max (I, j) chinaz
Reference content is as follows: Take the maximum value in I and j. For example, int x = math. Max (5, 10); // X, the value is 10. Add a bit. 23. String comparison ...... Add one.Webmaster Station |
23. String comparison is generally used: If (str1 = str2) {}, but there are other methods:
Webmaster Station
Reference content is as follows: (1 ), String str1; str2 // Syntax: str1.endswith (str2); _ check whether str1 ends with str2 and returns a Boolean value. For example: If (str1.endswith (str2) {response. Write ("string str1 ends with" + str2 + ");} (2 ), // Syntax: str1.equals (str2); _ check whether str1 is equal to str2. Return a Boolean value, which is the same as the preceding syntax. (3 ), // Syntax equals (str1, str2); _ checks whether str1 is equal to str2 and returns a Boolean value. [Chinese webmaster site] |
24. indexof (), lastindexof ()[Chinese webmaster site]
Reference content is as follows: Search for the position where the specified character or string appears for the first time (the last time) in the string, and return the index value, for example: Str1.indexof ("word"); // search for the index value (location) of the word in str1) Str1.indexof ("string"); // search for the index value (location) of the first character of "string" in str1) Str1.indexof ("string", 4th); // query the index value (location) of the first character of the "string" in str1 for 2 characters starting from str1 characters) Chinaz |
25. insert () chinaz
Reference content is as follows: Insert the specified character into the specified index position in the string. For example: Str1.insert (1, "word"); Insert "word" to the second character of str1. If str1 = "China", it is inserted as "Chinese country ";[Chinese webmaster site] |
26. padleft (), padright ()
Webmaster Station
Reference content is as follows: Add a space or a specified char character to the left (or right) of the string so that the string reaches the specified length, for example: <% String str1 = "Chinese "; Str1 = str1.padleft (10, '1'); // No second parameter is added with Space Response. Write (str1); // The result is "1111111 Chinese" and the string length is 10. %> Webmaster site |
27. Remove () [Chinese webmaster site]
reference content is as follows: delete a specified number of characters from the specified position string comparison is generally used: If (str1 = str2) {}, but there are other methods: chinaz |