The string class, the math class, and the DateTime class

Source: Internet
Author: User
Tags square root

String class

String a = "abcdef123456"; Note: The length of the string is counted from 0 onwards, such as: 0,1,2,3,4,5,6,7,8,9 ...

A.length; is a property that represents the length of the string ★
A[2]; A is a string in the beginning of a, 2 is the position in the string, starting from 0, [] is the index number, a[2] the output is C

A=a.trim (); Remove the left and right side of the space, you can not remove the space inside the string ★
A=a.trimstart (); Remove the left space
A=a.trimend (); Remove the space on the right


A=a.tolower (); Converts uppercase English characters in a string to lowercase
A=a.toupper (); Converts lowercase English characters in a string to uppercase

A=a.startswith ("a"); Match the beginning to see if it starts with a and returns TRUE or False
A=a.endswith ("6"); Match end, see if it ends with 6, returns TRUE or False
A=a.contains ("CD"); Matches whether the entire string contains a CD, returns TRUE or false★

A=a.indexof ("1"); Where a string appears in Str (where it first appears)
A=a.lastindexof ("2"): The last occurrence of a string in str

A=a.substring (5,4); Intercept string from fifth bit, intercept 4 bit ★

A=a.replace ("CD", "GG"); Replace all strings that match the string condition of the specified segment (Find Replace function), replace the CD in the string with GG

Math class:

Double n = 3.1415;
Math.Round (n,2); Rounds N, retains 2 digits after the decimal point
Math.ceiling (n); Take the smallest integer greater than the decimal
Math.floor (n); Take the largest integer less than the decimal number
Math.sqrt (a); Open square, square root
Math.pow (2,4); 2 of the 4-time Square

DateTime class:

DateTime d =datetime.now Gets the current time of the computer

DateTime d=new datetime (); Defines a new time, initially zero
int a = D.year; Year of extraction
int b = D.month; Extract Month
int c = D.day; Extract Date
int e = D.hour; Extraction hours
int f = d.minute; Extract minutes
int g = D.second; Extract seconds
int h = d.millisecond; Extracting milliseconds
int k = D.dayofyear; Date obtained is the day ordinal of the year
DayOfWeek L = d.dayofweek; The date is the week of the week

System.TimeSpan da = new TimeSpan (1,0,0,0);
D = D.add (DA);

D = d.addyears (1); Add one year
D = D.addmouth (1); Add one months
D = d.addday (1); Add a day
D = d.addhour (1); Add an hour
D = D.addminute (1); Add a minute
D = d.addseconds (1); Add one second

ToString ("yyyy mm month DD Day HH when mm minutes ss seconds") according to "Month Day and minute minute" to show out (hh means 12-hour system; HH denotes 24-hour system, and the year-to-date can be replaced by a surrogate, or can be replaced by several )

The string class, the math class, and the DateTime class

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.