C# String,Datetime,Math类

+++++String类+++++
黑色小扳手 - 属性
紫色立方体 - 方法


***字符串.Length - 字符串长度,返回int类型

字符串.TrimStart() - 去掉前空格
字符串.TrimEnd() - 去掉后空格
***字符串.Trim() - 去掉字符串的前后空格 string

***字符串.ToUpper() - 将字符串中的小写字符变成大写 string
***字符串.ToLower() - 变成小写 string

索引/下标
***字符串.SubString(a); - 截取字符串,a - 要开始截取的下标,包含下标所对应的字符
***字符串.SubString(a,b); - a - 下标 , b - 要截取几个字符(从1开始数)

***字符串.IndexOf("串"); - 返回字符串中第一个匹配项的索引,如果没有匹配项返回-1 int
int b = s.IndexOf("天",s.IndexOf("天")+1); //获得第二个匹配项,3 4 5 6

字符串.LastIndexOf("串"); - 返回最后一个匹配项的索引

***字符串.StartWidth("串"); - 判断是否以什么开头
***字符串.EndsWidth("串"); - 判断是否以什么结尾
******字符串.Contains("串"); - 判断是否包含 string

****s.Replace(要替换的字符串, 替换的字符串); - 字符替换 string
s.Remove(3); - 移除从索引到末尾的全部字符 string

+++++Math类+++++
Math.Pow(x,y); - 次方
Math.Sqrt(x); - 平方根

Math.Ceiling(double); - 取上限
Math.Floor(double); - 取下限
Math.Round(double); - 取四舍五入
Math.Abs(double); - 取绝对值

+++++DateTime类+++++
DateTime 变量名 = new DateTime(); - 定义

DateTime.Now; - 获取此电脑当前时间

.ToString("Format"); - 设置日期格式化,
yyyy-年 MM-月 dd-日 hh-12制小时 HH-24制小时 mm-分钟 ss-秒 ms-毫秒

.AddYears(); - 在此时间基础上增加多少年
.AddMonths(); - 增加月
.AddDays(); - 增加日
.AddHours(); - 增加小时
.AddMinutes(); - 增加分钟
.AddSeconds(); - 增加秒

.Year; - 获取此时间变量的年份
.Month; - 获取月份
.Day; - 日
.Hour; - 小时
.Minute; - 分钟
.Second; - 秒
.Millisecond; - 毫秒

.DayOfYear; - 获取当前日期是此年中的第几天
.DayOfWeek; - 获取是星期几

.TimeOfDay; - 获取时间部分
.Date; - 获取日期部分


TimeSpan类型 - 时间间隔类型
.Days - 差距多少天
.Hours - 一天中差距多少小时
.Minutes - 一天中差距多少分钟
.Seconds - 一天中差距多少秒
.Milliseconds - 毫秒

.Total.... 累计差距

 

String.split();



 

 

 

原文地址:https://www.cnblogs.com/yangchuanqi/p/7774235.html