Learning the function set that Asp. Net often uses

Source: Internet
Author: User
Tags servervariables
1. DateTime numeric type System. dateTime currentTime = new System. dateTime (); 1.1 returns the current year, month, day, hour, minute, second currentTime = System. dateTime. now; 1.2: the current year int year = currentTime. year; 1.3 the current month int month = currentTime. month; 1.4 the current day int day = currentTime. day; 1.5 when the current time is int = currentTime. hour; 1.6 get the current minute int minute = currentTime. minute; 1.7 takes the current second int seconds = currentTime. second; 1.8 takes the current millisecond int millisecond = currentTime. millisecond; (the variable can be in Chinese) 2. Int32.Parse (the variable) Int32.Parse ("constant ") Convert string to 32-digit font. 3. variable. toString () converted to string 12345. toString ("n"); // generate a 12,345.00 12345. toString ("C"); // generates $12,345.00 12345. toString ("e"); // generates the 1.234500e + 004 12345. toString ("f4"); // generate a 12345.0000 12345. toString ("x"); // generate 3039 (hexadecimal) 12345. toString ("p"); // generate 1,234,500.00% 4. variable. length: string str = "China"; int Len = str. length; // Len is a custom variable, str is the variable name of the string to be tested 5, System. text. encoding. default. ge Convert the tBytes (variable) code to a bit Code, for example, byte [] bytStr = System. text. encoding. default. getBytes (str); then we can get the bit length: len = bytStr. length; 6. System. text. the StringBuilder ("") string is added, and the (+ is the same ?) For example, System. text. stringBuilder sb = new System. text. stringBuilder (""); sb. append ("China"); sb. append ("people"); sb. append ("Republic"); 7. variables. substring (parameter 1, parameter 2); part of the truncated string. Parameter 1 is the left starting digit, and parameter 2 is the number of truncated digits. For example, string s1 = str. substring (0, 2); 8, String user_IP = Request. serverVariables ["REMOTE_ADDR"]. toString (); get the IP address of the remote user 9. Get the real IP address of the remote user through the proxy server: 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 () ;}10, Session ["variable"]; Access Session value; for example, Value assignment: Session ["username"] = ""; value: object objName = Session ["username"]; String strName = objName. toString (); clear: Session. removeAll (); 11, String str = Request. queryString ["variable"]; use a hyperlink to send a variable. For example, create a hyperlink on any page: <a href = Edit. aspx? Fbid = 23> click </a> in Edit. value on the aspx page: String str = Request. queryString ["fdid"]; 12. DOC object. createElement ("new node name"); create XML document new node 13, parent node. appendChild (child node); Add the new child node to the XML document parent node 14. parent node. removeChild (node); delete node 15, Response. write ("string"); Response. write (variable); output to the page. Response. redirect ("URL address"); jump to the page 16 and char specified by the URL. isWhiteSpce (string variable, number of digits) -- check whether the specified position is empty in logical mode; 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. 17. char. isPunctuation ('characters') -- check whether the logical character is a punctuation character, for example, Response. write (char. isPunctuation ('A'); // return: False 18, (int) 'character' to convert the character into A number, check the Code Point, note that it is A single quotation mark. For example: Response. Write (int) '); // The code with the result being a medium character: 20013 19. The (char) code converts the number into a character and queries the characters represented by the Code. For example: Response. Write (char) 22269); // return the word "country. 20. Trim () clears the leading and trailing spaces of the string 21 and string variables. replace ("substring", "Replace with") string replacement for example: string str = "China"; str = str. replace ("country", "Central"); // Replace the national character with the central character Response. write (str); // The output result is "Central", for example: (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 still be restored) Response. write (str); // It is displayed as follows: "This is a <script> script". If it is not replaced, <script> is not displayed. If it is a script, it runs, the script will not run. 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 the strSubmit. This method can also be used to easily implement the UBB code. 22. Math. max (I, j) obtains the maximum values in I and j, for example, int x = Math. max (5, 10); // Add the value of x to 10. 23. String comparison ...... add a bit. 23. string comparison is generally used: if (str1 = str2) {}, but there are other methods: (1), string str1; str2 // Syntax: str1.EndsWith (str2); _ checks whether str1 ends with str2 and returns a Boolean value. for example: if (str1.EndsWith (str2) {Response. write ("str1 ended with" + str2 + ");} (2), // Syntax: str1.Equals (str2 ); _ check whether str1 is equal to str2. A boolean value is returned. The usage is the same as that of str2. (3), // syntax Equals (str1, str2); _ checks whether str1 is equal to str2 and returns a Boolean value. The usage is the same as above. 24. IndexOf () and LastIndexOf () are used to search for the position of the specified character or string that appears for the first time (the last time). The index value, for example, str1.IndexOf ("word"), is returned "); // search for the index value (location) str1.IndexOf ("string") in str1; // 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) 25. Insert () specifies the index bit in the string to Insert the specified character. For example: str1.Insert (1, "word"); Insert "word" at the second character of str1. If str1 = "China", insert it as "Chinese "; 26. When PadLeft () and PadRight () are added to the left (or right) of the string with spaces or specified char characters, the string reaches the specified length, for example, <% string str1 = "Chinese "; str1 = str1.PadLeft (10, '1'); // No second parameter is added with a space Response. write (str1); // The result is "1111111 Chinese", the string length is 10%> 27, Remove () from the specified position to delete the specified number of character strings are generally used for comparison: if (str1 = str2) {}, but there are other methods: 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 ("str1 ended with" + str2 + ");} 2. // Syntax: str1.Equals (str2); _ check whether str1 is equal to str2, returns a Boolean value. The usage is the same as above. 3. // syntax Equals (str1, str2); _ checks whether str1 is equal to str2 and returns a Boolean value. indexOf () searches for the position where the specified character or string appears for the first time and returns the first index value, for example, str1.IndexOf ("word "); // search for the index value (location) str1.IndexOf ("string") in str1; // 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) 1.9 display Chinese date -- year, month, and day time string strY = cur Processing time. toString ("f"); // do not display seconds 1.10 take Chinese Date display _ year and month string strYM = currentTime. toString ("y"); 1.11 returns the Chinese Date display _ month-day string strMD = currentTime. toString ("m"); 1.12 is the current year, month, and day. Format: 2003-9-23 string strYMD = currentTime. toString ("d"); 1.13 returns the current time, in the format of 14: 24 string strT = currentTime. toString ("t"); updated, which cannot be edited: c #.. net functions and methods (add them together) 1. DateTime digital System. dateTime currentTime = new System. dateTime (); 1.1 returns the current year, month, day, hour, minute, second currentTime = Sy Stem. dateTime. now; 1.2: the current year int year = currentTime. year; 1.3 the current month int month = currentTime. month; 1.4 the current day int day = currentTime. day; 1.5 when the current time is int = currentTime. hour; 1.6 get the current minute int minute = currentTime. minute; 1.7 takes the current second int seconds = currentTime. second; 1.8 takes the current millisecond int millisecond = currentTime. millisecond; (the variable can be in Chinese) 1.9 display Chinese date -- year month day time string strY = currentTime. toString ("f"); // do not display seconds 1.10 take Chinese Date display _ year and month string strYM = currentTime. toString ("y"); 1.11 in progress Text date display _ month and day string strMD = currentTime. toString ("m"); 1.12 Chinese year month day string strYMD = currentTime. toString ("D"); 'www. knowsky. com1.13 returns the current time, in the format of 14: 24 string strT = currentTime. toString ("t"); 1.14 takes the current time, format: 2003-09-23T14: 46: 48 string strT = currentTime. toString ("s"); 1.15 takes the current time, format: 2003-09-23 14: 48: 30Z string strT = currentTime. toString ("u"); 1.16 takes the current time, format: string strT = currentTime. toString ("g"); 1. 17. Take the current time in the format of Tue, 23 Sep 2003 14:52:40 GMT string strT = currentTime. toString ("r"); 1.18 obtain the DateTime newDay = DateTime after the current time n days. now. addDays (100); 2. Convert Int32.Parse (variable) Int32.Parse ("constant") into 32-digit font. 3. variable. toString () converted to string 12345. toString ("n"); // generate a 12,345.00 12345. toString ("C"); // generates $12,345.00 12345. toString ("e"); // generates the 1.234500e + 004 12345. toString ("f4"); // generate a 12345.0000 12345. toString ("x "); // Generate 3039 (hexadecimal) 12345. toString ("p"); // generate 1,234,500.00% 4. variable. length: string str = "China"; int Len = str. length; // Len is a custom variable, str is the variable name of the string to be tested 5, System. text. encoding. default. convert the GetBytes (variable) code to a bit Code, for example, byte [] bytStr = System. text. encoding. default. getBytes (str); then we can get the bit length: len = bytStr. length; 6. System. text. the StringBuilder ("") string is added, and the (+ is the same ?) For example, System. text. stringBuilder sb = new System. text. stringBuilder (""); sb. append ("China"); sb. append ("people"); sb. append ("Republic"); 7. variables. substring (parameter 1, parameter 2); part of the truncated string. Parameter 1 is the left starting digit, and parameter 2 is the number of truncated digits. For example, string s1 = str. substring (0, 2); 8, String user_IP = Request. serverVariables ["REMOTE_ADDR"]. toString (); get the IP address of the remote user 9. Get the real IP address of the remote user through the proxy server: 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 () ;}10, Session ["variable"]; Access Session value; for example, Value assignment: Session ["username"] = ""; value: object objName = Session ["username"]; String strName = objName. toString (); clear: Session. removeAll (); 11, String str = Request. queryString ["variable"]; use a hyperlink to send a variable. For example, create a hyperlink on any page: <a href = Edit. aspx? Fbid = 23> click </a> in Edit. value on the aspx page: String str = Request. queryString ["fdid"]; 12. DOC object. createElement ("new node name"); create XML document new node 13, parent node. appendChild (child node); Add the new child node to the XML document parent node 14. parent node. removeChild (node); delete node 15, Response. write ("string"); Response. write (variable); output to the page. Response. redirect ("URL address"); jump to the page 16 and char specified by the URL. isWhiteSpce (string variable, number of digits) -- check whether the specified position is empty in logical mode; 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. 17. char. isPunctuation ('characters') -- check whether the logical character is a punctuation character, for example, Response. write (char. isPunctuation ('A'); // return: False 18, (int) 'character' to convert the character into A number, check the Code Point, note that it is A single quotation mark. For example: Response. Write (int) '); // The code with the result being a medium character: 20013 19. The (char) code converts the number into a character and queries the characters represented by the Code. For example: Response. Write (char) 22269); // return the word "country. 20. Trim () clears the leading and trailing spaces of the string 21 and string variables. replace ("substring", "Replace with") string replacement for example: string str = "China"; str = str. replace ("country", "Central"); // Replace the national character with the central character Response. write (str); // The output result is "Central", for example: (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 still be restored) Response. write (str); // It is displayed as follows: "This is a <script> script". If it is not replaced, <script> is not displayed. If it is a script, it runs, the script will not run. 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 the strSubmit. This method can also be used to easily implement the UBB code. 22. Math. max (I, j) obtains the maximum values in I and j, for example, int x = Math. max (5, 10); // x will be set to 10 23, string comparison is generally used: if (str1 = str2) {}, but there are other methods: (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 ("str1 ended with" + str2 + ");} (2), // Syntax: str1.Equals (str2 ); _ check whether str1 is equal to str2. A boolean value is returned. The usage is the same as that of str2. (3), // syntax Equals (str1, str2); _ checks whether str1 is equal to str2 and returns a Boolean value. The usage is the same as above. 24. IndexOf (), LastIndex Of () searches for the position where the specified character or string appears for the first time (the last time) in the string, and returns the index value, for example, str1.IndexOf ("word "); // search for the index value (location) str1.IndexOf ("string") in str1; // 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) 25. Insert () specifies the index bit in the string to Insert the specified character. For example: str1.Insert (1, "word"); Insert "word" at the second character of str1. If str1 = "China", insert it as "Chinese "; 26. When PadLeft () and PadRight () are added to the left (or right) of the string with spaces or specified char characters, the string reaches the specified length, for example, <% string str1 = "Chinese "; str1 = str1.PadLeft (10, '1'); // No second parameter is added with a space Response. write (str1); // The result is "1111111 Chinese", the string length is 10%> 27, Remove () delete the specified number of characters from the specified position <% string str1 = "I am one of the followers of Saddam"; Response. write (str1.Remove (5, 4); // The result is "I am one of Saddam" %>

  

Related Article

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.