C # common code for obtaining remote access IP addresses

Source: Internet
Author: User
Tags servervariables
1. Obtain the current button:

Private void textbox1_keydown (Object sender, system. Windows. Forms. keyeventargs E)
{
If (E. keycode. tostring () = "enter ")
{

MessageBox. Show (E. keycode. tostring (), "The health you are pressing is :");
}
}

 

2. datetime numeric type

System. datetime currenttime = new system. datetime ();
1.1 take the current year, month, day, hour, minute, second
Currenttime = system. datetime. now;
1.2 get current year
Int year = currenttime. Year;
1.3 take the current month
Int month = currenttime. month;
1.4 get the current day
Int day = currenttime. Day;
1.5 current time
Int = currenttime. hour;
1.6 get the current score
Int = currenttime. minute;
1.7 takes the current second
Int second = 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, and day
String stry = currenttime. tostring ("F"); // seconds not displayed

1.10 use Chinese date to display _ year and month
String strym = currenttime. tostring ("Y ");

1.11 retrieve Chinese Date display _ month/day
String strmd = currenttime. tostring ("M ");

1.12 Chinese year, month, and day
String strymd = currenttime. tostring ("D ");

1.13 get the current time, format: 14: 24
String strt = currenttime. tostring ("T ");

1.14 obtain the current time in the format of 2003-09-23t14: 46: 48
String strt = currenttime. tostring ("S ");

1.15 obtain the current time in the format of 2003-09-23 14: 48: 30z
String strt = currenttime. tostring ("U ");

1.16 The current time. format:
String strt = currenttime. tostring ("G ");

1.17 take the current time, format: Tue, 23 Sep 2003 14:52:40 GMT
String strt = currenttime. tostring ("R ");

1.18 obtain the date and time of the current time n days later
Datetime newday = datetime. Now. adddays (100 );

2. Convert string type to 32-digit font

Int32.parse (variable) int32.parse ("constant ")

3. Variable. tostring ()
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%

4. Variable. Length numeric type

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.

5. system. Text. encoding. Default. getbytes (variable)

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;

6. system. Text. stringbuilder ("")

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 ");

7. Variable. substring (parameter 1, parameter 2 );

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 );

8. Obtain the IP address of a remote user.

String user_ip = request. servervariables ["remote_addr"]. tostring ();
Obtain the IP address of a remote user

9. Obtain 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, assign a value: session ["username"] = "";

Value: Object objname = session ["username"];
String strname = objname. tostring ();
Clear: Session. removeall ();

11. String STR = request. querystring ["variable"];

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"];

12. Create a new node for the XML document

Doc object. createelement ("new node name ");

13. parent node. appendchild (child node );

Add the new child node to the XML document parent node.

14. delete a node

Parent node. removechild (node );

15. Response

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 type

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.

17. Char. ispunctuation ('characters') -- Logical type

Check whether a character is a punctuation mark.
For example: Response. Write (char. ispunctuation ('A'); // return: false

18. (INT) 'characters'

Convert the character into a number and check the code. Note that it is a single quotation mark.
For example:
Response. Write (INT) 'in'); // The code with the result of a Chinese character: 20013

19. (char) Code

Convert the number into characters and check the characters represented by the Code.
For example:
Response. Write (char) 22269); // return the word "country.

20. Clear spaces before and after the string

Trim ()

21. string variable. Replace ("substring", "Replace ")

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

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.