C # Common Function method set
Last Update:2017-02-28
Source: Internet
Author: User
Function 1, DateTime digital type
System.DateTime currenttime=new System.DateTime ();;
1.1 to take the current month and the day seconds
Currenttime=system.datetime.now;;
1.2 Take as the year before last
int year =currenttime.year;;
1.3 Take the current month
int month =currenttime.month;;
1.4 Take the current day
int day =currenttime.day;;
1.5 Take current time
int when =currenttime.hour;;
1.6 Take the current score
int cent =currenttime.minute;;
1.7 Take the current second
int seconds =currenttime.second;;
1.8 Take the current millisecond
int millisecond =currenttime.millisecond;;
(Variables available in Chinese)
2, int32.parse (variable) int32.parse ("constant")
Conversion of character to 32-digit number
3, variable. ToString ()
Character conversion 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 (16 binary)
12345.ToString ("P");;//Generate 1,234,500.00%
4, variable. Length Number Type
Length of string:
such as: string str= "China";;
int Len = str. Length;;//len is a custom variable, str is the variable name of the measured string
5, System.Text.Encoding.Default.GetBytes (variable)
codewords conversion to bit code
such as: byte[] bytstr = System.Text.Encoding.Default.GetBytes (str);
Then you can get the bit length:
len = bytstr.length;;
6, System.Text.StringBuilder ("")
string addition, (+ is not the same?) )
such as: System.Text.StringBuilder SB = new System.Text.StringBuilder ("");
Sb. Append ("China");;
Sb. Append ("people");;
Sb. Append ("Republic");;
7, variable. Substring (parameter 1, parameter 2);;
Intercepts a portion of the string, parameter 1 is the left starting bit, and the parameter 2 is the Intercept number.
such as: string S1 = str. Substring (0,2);
8, String user_ip=request.servervariables["REMOTE_ADDR"]. ToString ();;
Take remote User IP address
9, through the proxy server to take remote user real IP address:
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, assignment: session["username"]= "little Bush";
Value: Object objname=session["username"];
String strname=objname.tostring ();;
Empty: Session.removeall ();;
11. String str=request.querystring["variable"];
Transfer variables by using hyperlinks.
If you build hyperlinks on either page: 〈a href=edit.aspx?fbid=23〉 Click 〈/a〉
Value in edit.aspx page: String str=request.querystring["Fdid"];;
12. Doc object. createelement ("new section named")
Create a new node for an XML document
13, the parent node. AppendChild (child nodes);
Add a new child node under the XML Document parent node
14, the parent node. RemoveChild (node);;
Delete a node
15, Response
Response.Write ("string");
Response.Write (variable);
Output to the page.
Response.Redirect ("URL address");
Jumps to the page specified by the URL
16, Char. ISWHITESPCE (string variable, number of digits)--Logical type
Check whether the specified position is empty character;
Such as:
String str= "Chinese people";;
Response.Write (Char. Iswhitespace (str,2));;//Result: True, the first character is 0 digits, and 2 is the third character.
17, Char. Ispunctuation (' character ')--logical type
Whether Chag is a punctuation mark
such as: Response.Write (char. Ispunctuation (' A '));;//return: False
18, (int) ' character '
Turn the characters into numbers, check the code points, and note the single quotes.
Such as:
Response.Write ((int) ' in ');;//result is the code for the word: 20013
19, (char) code
Turn the numbers into characters and look up the characters represented by the code.
Such as:
Response.Write ((char) 22269);;//return; country "word.
20, Trim ()
Clear a space before and after a string
21, string variables. Replace ("substring", "Replace with")
String substitution
Such as:
String str= "China";;
Str=str. Replac