C # .NET common functions and method sets

xiaoxiao2021-03-06  18

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:

Such as:

String str = "China";

Int Len

= Str.Length;

// LEN is a custom variable, Str is a variable name of the string of the test

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.ispunctuation ('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);

// Return to 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");

// Replace the national word to CCR RESPONSE.WRITE (STR);

// The output is "central"

Another example: (this very practical)

String str = "This is