Very strong C # .NET functions list

xiaoxiao2021-03-06  71

1, DateTime Digital

System.datetime CurrentTime = new system.datetime ();

1.1 Take the first day of the month

CurrentTime = system.datetime.now;

1.2 taken the previous year

INT year = currenttime.year;

1.3 take the previous month

Int month = currenttime.month;

1.4 Take the day

INT day = currenttime.day;

1.5 Take the current time

INT = currenttime.Hour;

1.6 take the front part

INT = CURRENTTIME.MINUTE;

1.7 take the second second

INT second = currenttime.second;

1.8 takes the current millisecond

INT millisecond = currenttime.millisecond;

(Variable can be available in Chinese)

2, int32.parse (variable) INT32.PARSE ("constant")

Character conversion to 32-bit digital

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)

12345.Tostring ("P"); // Generate 1,234,500.00%

4, variable .length digital type

Take a string length:

String str = "China";

INT len = str.length; // LEN is a custom variable, Str is a variable name of the string of the measured string

5, System.Text.Encoding.default.getbytes (variable)

Frame conversion to a specific 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 ("" ")

The string is added, ( 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);

Part of the interception string, the parameter 1 is the left start bit number, and the parameter 2 is a few digits.

Such as: string s1 = str.substring (0, 2);

8, string user_ip = request.servervariables ["remote_addr"]. TOSTRING ();

Take a remote user IP address

9, through the proxy server to take a 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 the session value;

For example, assignment: session ["username"] = "small Bush";

Value: object objname = session ["username"];

String strname = Objname.toString ();

Empty: session.removeall ();

11, string str = request.queryString ["Variable"];

Use hyperlink to transfer variables.

Just in any page:

Take the value in the Edit.aspx page: string str = request.queryString ["fdid"];

12, DOC object .createElement ("New Node Name");

Create an XML document new node

13, parent node .Appendchild (child node);

Add the newly created child node to the XML document parent node

14, parent node. Removechild (node);

Delete node

15, Response

Response.write ("string");

Response.write;

Output to the page.

Response.Redirect ("URL Address");

Jump to the page specified by the URL

16. Char.iswhitespce (string variable, bit) - logical type

Check if the specified position is empty characters;

Such as:

String str = "Chinese people";

Response.write (char.iswhitespace (STR, 2)); / / The result is: True, the first character is 0 bits, 2 is the third character.

17, char.ispuncture ('character') - logical type

Is it a punctuation?

Such as: response.write (char.ispunctuation ('a')); // Return: false

18, (int) 'character'

Turn characters to numbers, check the code points, and pay attention to single quotes.

Such as:

Response.write ((int) '); / / The result is the code: 20013

19, (char) code

Turn the number into characters, check the characters represented by the code.

Such as:

Response.write (CHAR) 22269); // Returns the "National" word.

20, TRIM ()

Clear strings before and after space

21, string variables.Replace ("Sub string", "replace")

String replacement

Such as:

String str = "China";

Str = str.replace ("Country", "Central"); // exchange national characters to CCR

Response.write (STR); // output result is "central"

Another example: (this very practical)

String str = "This is the