C#函数集合(四)

 
22、Math.Max(i,j)
取i与j中的最大值
如 int x=Math.Max(5,10); // x将取值 10

加一点吧 23、字串对比......
加一点吧

23、字串对比一般都用: if(str1==str2){ } , 但还有别的方法:

(1)、
string str1; str2
//语法: str1.EndsWith(str2); __检测字串str1是否以字串str2结尾,返回布尔值.如:
if(str1.EndsWith(str2)){ Response.Write("字串str1是以"+str2+"结束的"); }

(2)、
//语法:str1.Equals(str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.

(3)、
//语法 Equals(str1,str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.

24、IndexOf() 、LastIndexOf()
查找字串中指定字符或字串首次(最后一次)出现的位置,返回索引值,如:
str1.IndexOf("字"); //查找“字”在str1中的索引值(位置)
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找“字串”的第一个字符在str1中的索引值(位置)

25、Insert()
在字串中指定索引位插入指定字符。如:
str1.Insert(1,"字");在str1的第二个字符处插入“字”,如果str1="中国",插入后为“中字国”;

26、PadLeft()、PadRight()
在字串左(或右)加空格或指定char字符,使字串达到指定长度,如:
<%
string str1="中国人";
str1=str1.PadLeft(10,'1'); //无第二参数为加空格
Response.Write(str1); //结果为“1111111中国人” , 字串长为10
%>

27、Remove()
从指定位置开始删除指定数的字符
字串对比一般都用: if(str1==str2){ } , 但还有别的方法:

1、
string str1; str2
//语法: str1.EndsWith(str2); __检测字串str1是否以字串str2结尾,返回布尔值.如:
if(str1.EndsWith(str2)){ Response.Write("字串str1是以"+str2+"结束的"); }

2、
//语法:str1.Equals(str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.

3、
//语法 Equals(str1,str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.

IndexOf()
查找字串中指定字符或字串首次出现的位置,返首索引值,如:
str1.IndexOf("字"); //查找“字”在str1中的索引值(位置)
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找“字串”的第一个字符在str1中的索引值(位置)

1.9 取中文日期显示——年月日时分
string strY=currentTime.ToString("f"); //不显示秒

1.10 取中文日期显示_年月
string strYM=currentTime.ToString("y");

1.11 取中文日期显示_月日
string strMD=currentTime.ToString("m");

1.12 取当前年月日,格式为:2003-9-23
string strYMD=currentTime.ToString("d");

1.13 取当前时分,格式为:14:24
string strT=currentTime.ToString("t");
更新一下, 上面不能编辑:

c#.net函数和方法集(大家一起来加啊)


1、DateTime 数字型
System.DateTime currentTime=new System.DateTime();
1.1 取当前年月日时分秒
currentTime=System.DateTime.Now;
1.2 取当前年
int 年=currentTime.Year;
1.3 取当前月
int 月=currentTime.Month;
1.4 取当前日
int 日=currentTime.Day;
1.5 取当前时
int 时=currentTime.Hour;
1.6 取当前分
int 分=currentTime.Minute;
1.7 取当前秒
int 秒=currentTime.Second;
1.8 取当前毫秒
int 毫秒=currentTime.Millisecond;
(变量可用中文)

1.9 取中文日期显示——年月日时分
string strY=currentTime.ToString("f"); //不显示秒

1.10 取中文日期显示_年月
string strYM=currentTime.ToString("y");

1.11 取中文日期显示_月日
string strMD=currentTime.ToString("m");

1.12 取中文年月日
string strYMD=currentTime.ToString("D");

1.13 取当前时分,格式为:14:24
string strT=currentTime.ToString("t");

1.14 取当前时间,格式为:2003-09-23T14:46:48
string strT=currentTime.ToString("s");

1.15 取当前时间,格式为:2003-09-23 14:48:30Z
string strT=currentTime.ToString("u");

1.16 取当前时间,格式为:2003-09-23 14:48
string strT=currentTime.ToString("g");

1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT
string strT=currentTime.ToString("r");

1.18获得当前时间 n 天后的日期时间
DateTime newDay = DateTime.Now.AddDays(100);

转载于:https://www.cnblogs.com/c546170667/archive/2011/05/22/2053630.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值