C # common function tables

Source: Internet
Author: User
Tags natural logarithm square root truncated

1. datetime numeric type
system. datetime currenttime = new system. datetime ();
1.1 returns the current year, month, day, hour, minute, and second
currenttime = system. datetime. now;
1.2 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 get current time
int time = currenttime. hour;
1.6 returns the current score
int score = currenttime. minute;
1.7 takes the current second
int second = currenttime. second;
1.8 returns the current millisecond
int millisecond = currenttime. millisecond;
(the variable can be in Chinese) 2. int32.parse (variable) int32.parse (constant)
convert string type to 32-digit font
1.9 display Chinese date -- year, month, and day
string stry = currenttime. tostring (f); seconds not displayed
1.10 display in Chinese Date _ year and month
string strym = currenttime. tostring (y);
1.11 use the Chinese date to display the _ month and day
string strmd = currenttime. tostring (m);
1.12 indicates the current year, month, and day, in the format of 2003-9-23
string strymd = currenttime. tostring (d);
1.13 The current time, in the format of 14: 24
string strt = currenttime. tostring (t);

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

7. Variable. substring (parameter 1, parameter 2 );
Similar to the left, right, and mid functions in VB.
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 );
Parameter 2 can be set to the default value, indicating that the string end is obtained from parameter 1. For example:
String A = ABC;
A. substring (1)
Is BC.

8. 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 [variables];
Access session value;
For example, assign a value: session [username] = bush;

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 href = edit. aspxfbid = 23 on any page and click.
On the edit. ASPX page, set the value to string STR = request. querystring [fdid].

12. Doc object. createelement (new node name );
Create a new node for the XML document

13. parent node. appendchild (child node );
Add the new child node to the XML document parent node.

14. parent node. removechild (node );
Delete a 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); Result: True, the first character is 0, 2 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 characters into numbers and queryCodePoint, note that it is single quotes.
For example:
Response. Write (INT) '); the result is the code of the 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); returns the country character.

20. Trim ()
Clear leading and trailing Spaces

21. string variable. Replace (Child string, replace)
String replacement
For example:
String STR = China;
STR = Str. Replace (national, central); replace the national character with the central character
Response. Write (STR); the output result is central.

Another example is: (this is very practical)

String STR = This is a script;
STR = Str. Replace (, fontfont); replace the left angle bracket with font and font (or replace it with, but it is estimated that after saving XML, it will be restored again)
Response. Write (STR); displayed as: This is a script

If it is not replaced, the script will not be displayed. If it is a script, it will run. If it is replaced, 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 ID of the control that you want users to submit data.
Strsubmit = strsubmit. Replace (, fontfont );
Then save or output strsubmit.
This method can also be used to easily implement the UBB code.

22. Math. Max (I, j)
Take the maximum value in I and j.
For example, int x = math. Max (5, 10); X is set to 10.

23. String comparison generally uses 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, as shown in figure
If (str1.endswith (str2) {response. Write (string str1 ends with + str2 + );}

(2 ),
Syntax str1.equals (str2); _ checks whether str1 is equal to str2 and returns a Boolean value.

(3 ),
Syntax equals (str1, str2); _ checks whether str1 is equal to str2 and returns a Boolean value.

24. indexof (), lastindexof ()
Search for the position where the specified character or string appears for the first time (the last time) in the string, and return the index value, for example:
Str1.indexof (Word); search for the index value (location) of a word in str1)
Str1.indexof (string); searches for the index value (position) of the first character of the string in str1)
Str1.indexof (string, 4th); search for 2 characters starting from str1 and the index value (position) of the first character of the string in str1)

25. insert ()
Insert the specified character into the specified index position in the string. For example:
Str1.insert (1, word); insert a word at the second character of str1. If str1 = China, It is inserted as a Chinese character;

26. padleft (), padright ()
Add a space or a specified char character to the left (or right) of the string so that the string reaches the specified length, for example:
%
String str1 = Chinese;
Str1 = str1.padleft (10, '1'); no second parameter is added with Space
Response. Write (str1); the result is 1111111 Chinese, and the string length is 10
%

27. Remove ()
Deletes a specified number of characters from a specified position.
String comparison generally uses 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, as shown in figure
If (str1.endswith (str2) {response. Write (string str1 ends with + str2 + );}

2,
Syntax str1.equals (str2); _ checks whether str1 is equal to str2 and returns a Boolean value.

3,
Syntax equals (str1, str2); _ checks whether str1 is equal to str2 and returns a Boolean value.

Indexof ()
Searches for the position of the specified character or string that appears for the first time in the string, and returns the first index value, for example:
Str1.indexof (Word); search for the index value (location) of a word in str1)
Str1.indexof (string); searches for the index value (position) of the first character of the string in str1)
Str1.indexof (string, 4th); search for 2 characters starting from str1 and the index value (position) of the first character of the string in str1)

================= Asp.net (C #) common function table ==================================< br> ABS (number) gets the absolute value of the value.
ASC (string) obtains the first character ASCII code of the string expression.
ATN (number) gets the arc tangent of an angle.
callbyname (object, procname, usecalltype, [ARGs ()]) is used to execute the method, set, or return the attributes of an object.
the cbool (expression) Conversion expression is of the boolean type.
the cbyte (expression) Conversion expression is a byte type.
the cchar (expression) Conversion expression is in quiet state.
the cdate (expression) Conversion expression is of the date type.
the cdbl (expression) Conversion expression is of the double type.
the cdec (expression) Conversion expression is of the decimal type.
the CINT (expression) Conversion expression is of the integer type.
the clng (expression) Conversion expression is of the long type.

the cobj (expression) Conversion expression is of the object type.
the cshort (expression) Conversion expression is of the short type.
the csng (expression) Conversion expression is of the single type.
the CSTR (expression) Conversion expression is of the string type.
choose (index, choice-1 [, choice-2,... [, choice-N]) selects and returns the set parameters based on the index value.
CHR (charcode) obtains the character content in ASCII code.
close (filenumberlist) ends the archive enabled with open.
CoS (number) obtains the cosine of an angle.
type of the ctype (expression, typename) Conversion expression.
dateadd (dateinterval, number, datetime) adds or subtracted date or time.
datediff (dateinterval, date1, date2) calculates the difference between two dates or times.
datepart (dateinterval, date) returns the year, month, day, or time based on the received date or time parameter.
dateserial (year, month, day) combines the received parameters into a data of date type only.
datevalue (datetime) obtains the date value that conforms to the country-specific style and contains the time.

day (datetime) is sent back to the day based on the received date parameter.
EOF (filenumber) returns true when it reaches the end of an opened file.
exp (number) returns the power of e Based on the received parameter.
filedatetime (pathname) returns the date and time when the file was created.
the length of the file returned by filelen (pathname), in bytes.
filter (sourcearray, Match [, include [, compare]) searches for the specified string in the string array. All array elements contain the specified string, they are combined into a new string array and returned. If you want to return an array element that does not contain the specified string, set the include parameter to false. The compare parameter is used to set whether the search is case sensitive. In this case, you only need to give textcompare constants or 1.
fix (number) removes the fractional part of the parameter and returns the result.
Format (expression [, style [, firstdayofweek [, firstweekofyear]) converts the date, time, and value data into acceptable formats for each country.
formatcurrency (expression [, numdigitsafterdecimal [, includeleadingdigit]) outputs the value as the amount type.
the numdigitsafterdecimal parameter indicates the number of decimal words. The maximum deleadingdigit parameter indicates whether to add the number of words to an integer when the integer is 0.

formatdatetime (date [, namedformat]) returns formatted date or time data.
formatnumber (expression [, numdigitsafterdecimal [, includeleadingdigit]) returns the formatted value data. The numdigitsafterdecimal parameter indicates the number of decimal words, And the deleadingdigit parameter indicates whether to fill in the number of integer words when the integer is 0.
formatpercent (expression [, numdigitsafterdecimal [, includeleadingdigit]) returns numerical data converted to the percentage format. The numdigitsafterdecimal parameter indicates the number of decimal words, And the deleadingdigit parameter indicates whether to fill in the number of integer words when the integer is 0.
getattr(2005620163726.htm) returns the attribute value of the file or directory.
hex (number) converts a value to a hexadecimal value.
the hour field of the time returned by hour (time). The type is integer.
IIF (expression, truepart, falsepart) executes the program of the truepart field when the return value of the expression is true. , otherwise, execute the falsepart field.
instr ([start,] string1, string2) searches for the characters set by the string2 parameter to appear in the nth character of the string. Start is searched for by the nth character, string1 is the string to be searched, and string2 is the character to be searched.
int (number) returns an integer less than or equal to the maximum integer of the received parameter.
isarray (varname) determines whether a variable is of the array type. If it is an array, true is returned. Otherwise, false is returned.

isdate (expression) determines whether the expression content is of the datetime type. If the expression content is of the datetime type, true is returned. Otherwise, false is returned.
isdbnull (expression) determines whether the expression content is null. If it is null, true is returned. Otherwise, false is returned.
isnumeric (expression) determines whether the expression content is in a numeric state. If it is true, true is returned. Otherwise, false is returned.
join (sourcearray [, delimiter]) merges string arrays into unique strings. The delimiter parameter is set to add new strings to each element.
lcase (string) converts a string to a lowercase font.
left (string, length) gets the characters with the length parameter set from the left side of the string.
Len (string) gets the length of the string.
log (number) obtains the natural logarithm of a value.
ltrim (string) removes the left blank part of the string.
mid (string, start [, length]) extracts the string of the length after the character set by the Strat parameter in the string. If the length parameter is not set, all characters after start are retrieved.
minute (time) gets the time content in the specified part. The type is integer.
Create a new directory using mkdir (PATH.
month (date) indicates the month of the date. The type is integer.

monthname (month) is used to obtain the complete description of the month based on the received month value.
now () obtains the current date and time.
OCT (number) converts a value to an octal value.
Replace (expression, find, replace) converts the string specified by the find parameter in the string to the string specified by the replace parameter.
right (string, length) is a character set by the length parameter, which is obtained from the right of the string.
rmdir (PATH) removes an empty directory.
RND () is used to obtain decimal places between 0 and 1. If different values are to be obtained each time, randomize must be added before use.
rtrim (string) removes the white space on the right of the string.
the second part of the time content obtained by second (time). The type is integer.
the value obtained by sign (number) is positive or negative. positive returns 1, negative returns-1, and 0 returns 0.
sin (number) obtains the sine of an angle.
space (number) gets the blank string set by the number parameter.

Split (expression [, delimiter]) Splits a string into a String Array Based on the condition string set by the delimiter parameter.
SQRT (number) returns the square root of a number.
STR (number) converts a number into a string and returns it.
Strreverse (expression) returns the result after the string content is reversed.
Tan (number) returns the tangent of an angle.
Timeofday () gets the time that does not contain the date currently.
Timer () gets the number of seconds from 000 to the current time. The type is double.
Timeserial (hour, minute, second) combines the received parameters into a data with only the time date type.
Timavalue (time) gets the time value that matches the country-specific style.
Today () gets the date that today does not contain the time.
Trim (string) removes the white space at the beginning and end of the string.
Typename (varname) gets the type of the variable or object.
Ubound (arrayname [, dimension]) obtains the final index value of the array. The dimension parameter is used to obtain the final index value of the dimension.

Ucase (string) converts a string to uppercase.
Val (string) converts a numeric string to a numeric State. If the string contains non-numeric content, it is removed and merged into a number.
In the weekday (date) parameter, the date is the day of the week, Sunday is 1, Monday is 2, and Tuesday is 3.
Weekdayname (number) gets the name of the week according to the received parameter. The parameters that can be received are 1 to 7, and the parameters that can be received are 1 on Sunday, 2 on Monday, and 3 on Tuesday.

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.