First, the String class
1, length of the long character
string x = Console.ReadLine ();
int i = x.length;//length is the number of strings to get (starting from 1)
Console.Write (i);
Console.ReadLine ();
2.
x = X.trim ();//***trim () * * * can remove spaces before and after a string
TrimStart () Remove the preceding space, TrimEnd () remove the trailing space
3.
Substring (starting position, intercept length)
Substring (start position) write only start position, can intercept to tail
String p = x.substring (A, b);
The index is to intercept a string from bit a at 0, intercept b
Substring the first number is the index from which to intercept, the second is the length of the Intercept
Case: ID card interception Birthday
4,ToUpper () all uppercase;ToLower () all lowercase
x = X.tolower ();//Convert uppercase English characters in a string to lowercase
x = X.toupper ();//The lowercase English characters in the string are converted to uppercase
5. Replace ("Old word", "new word") replaces old word with new word
Replace ("", "");//Replaces all strings that match the string condition of the specified segment
6.
IndexOf ("string") returns the index of the first occurrence of this string
LastIndexOf ("string") returns the index of the last occurrence of this string
Whether Startwith ("string") starts with this string, returns True or False
Whether EndsWith ("string") ends with this string
Whether the Contains ("string") contains this string. Returns TRUE or False
Writing:
String ss= "Aasdfddscwefergreginlknsjooe";
int I=ss.indexof ("i");//The index where the first such character is located
int J=ss. Lastindesof ("J");//The index where the last such character is located
BOOL B=ss. StartsWith ("ABV");//whether to start with such a character, return ture or False
BOOL C=ss. EndsWith ("987");//whether to end with such a character,
BOOL D=ss. Contains ("ABC");//Whether it contains such a character, returns TRUE or False
7. #用法
Double d = 765765876583533.13;
string s = d.tostring ("#,#.00");//Draw a comma for every three bits before the decimal point
string s = d.tostring ("#.00");//The display 00 after the decimal point, some display itself
string s = d.tostring ("#.##");//The integer part is displayed after the decimal point, and some display itself
Double b = Double. Parse (Console.ReadLine ());
b = Math.Round (b);//odd. 5 obtained is on-line, even. 5 Get is offline
Second, themath class:
Ceiling () Take the line
Floor () Remove line
Math.PI Pi
Math.sqrt () square root
Math.Round () Rounding (note the odd even number. 5 different results)
Writing:
Double A = Math.PI; Pi
A = Math.sqrt (a); Square root
Math.Round (); Rounded
Math.ceiling (); Take online
Math.floor (); Remove Line
Console.WriteLine (a);
Console.ReadLine ();
Third, DateTime class (note that you need to initialize it before you use it.) )
1.
DateTime DT =new datetime ();//If you get the current time, you can not initialize:
DateTime dt = datetime.now;//The current time on the computer that was taken for a moment
Console.WriteLine (DT);
int nian = dt. Year;//get the year alone
int YUE=DT. month;//to get the month alone
int TIAN=DT. day;//Simple Acquisition Date
int SHI=DT. hour;//hours
int fen = dt. minute;//min
int miao = dt. second;//sec
int g = dt. dayofyear;//get Date is the day of the year
DayOfWeek d = dt. dayofweek;//gets the day of the week and gets to the English language. If you want to use Chinese, first d. ToString (), and then print out Chinese according to English.
Case:
2. Placeholder
YYYY-year
MM-Moon Month
dd--Day
HH--When hour
MM-minute Minut
SS-SEC Second
The above is a placeholder. This space can be used first in the string.
string s = dt. ToString ("yyyy mm month DD Day hh" mm minutes ss seconds ");
Case:
(1),
(2), input must be in a DateTime format before it can be accepted.
3, dt. Add
10,000 days ago is:
Add () Add or subtract a certain time interval
AddYears () Increase or subtract year
AddMonths () Add or subtract months
AddDays () Increase or subtract days
And so on
Note that the number of days to add and subtract is to take advantage of the double type. Others are of type int
4.TimeSpan
System.TimeSpan time = new TimeSpan ();//timespan is an interval type up to days (days, hours, minutes, seconds,)
DT = dt. ADD (time);
Three, exercises
1. Randomly generate a four-digit verification code
2, enter the number of days n, print out n days is the day of the week
Friday
Classes in C #