1、DateTime 数字型
System.DateTime currentTime=new System.DateTime(); 中国南通服务器网,为中文网南通服务器网,为中文网南通服务器网
1.2 取当前年
南通服务器网
int 年=currentTime.Year;
中国南通服务器网
1.3 取当前月
[南通服务器网]
int 月=currentTime.Month; 南通服务器网
1.4 取当前日 Spdns^com
int 日=currentTime.Day; 南通服务器网
1.5 取当前时
Www@Spdns@com
int 时=currentTime.Hour;
Spdns^com
1.6 取当前分
Www_Spdns_com
int 分=currentTime.Minute;
中国.南通服务器网
1.7 取当前秒
Spdns@com
int 秒=currentTime.Second;
[南通服务器网]
1.8 取当前毫秒
Spdns_com
int 毫秒=currentTime.Millisecond;
Spdns.com
(变量可用中文) Spdns
1.9 取中文日期显示——年月日时分
Www_Spdns_com
string strY=currentTime.ToString("f"); //不显示秒
Www^Spdns^com
1.10 取中文日期显示_年月
Www.Spdns.com
string strYM=currentTime.ToString("y"); Spdns@com
1.11 取中文日期显示_月日 Www~Spdns~com
string strMD=currentTime.ToString("m"); Spdns_com
1.12 取当前年月日,格式为:2003-9-23 中国南通服务器网
string strYMD=currentTime.ToString("d"); 中国南通服务器网
1.13 取当前时分,格式为:14:24 Spdns.com
string strT=currentTime.ToString("t"); 南通服务器网
2、Int32.Parse(变量) Int32.Parse("常量")
Spdns_com
字符型转换 转为32位数字型 中国南通服务器网,为中文网南通服务器网
12345.ToString("C"); //生成 ¥12,345.00
Spdns_com
12345.ToString("e"); //生成 1.234500e+004 南通服务器网
12345.ToString("f4"); //生成 12345.0000
中国南通服务器网,为中文网南通服务器网
12345.ToString("p"); //生成 1,234,500.00%
南通服务器网
4、变量.Length 数字型 Spdns_com
取字串长度: 中国.南通服务器网
如: string str="中国";
Spdns^com
int Len = str.Length ; //Len是自定义变量, str是求测的字串的变量名
Www@Spdns@com
5、System.Text.Encoding.Default.GetBytes(变量) 中.国.南通服务器网
字码转换 转为比特码 Www@Spdns@com
如:byte[] bytStr = System.Text.Encoding.Default.GetBytes(str);
南通服务器网
然后可得到比特长度: Spdns
len = bytStr.Length; 中.国.南通服务器网
6、System.Text.StringBuilder("")
Spdns
字符串相加,(+号是不是也一样?)
Www^Spdns^com
如:System.Text.StringBuilder sb = new System.Text.StringBuilder("");
Spdns@com
sb.Append("中华");
中国南通服务器网,为中文网南通服务器网
如:string s1 = str.Substring(0,2);
中.国.南通服务器网
8、String user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();
Www~Spdns~com
取远程用户IP地址
Spdns_com
9、穿过代理服务器取远程用户真实IP地址: Www@Spdns@com
以下为引用的内容: 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(); } |
Spdns_com
10、 Session["变量"]; 中国南通服务器网
存取Session值; Spdns.com
如,赋值: Session["username"]="小布什";
[南通服务器网]
取值: Object objName=Session["username"];
中.国.南通服务器网
String strName=objName.ToString(); 中国.南通服务器网
清空: Session.RemoveAll();
中国南通服务器网
11、String str=Request.QueryString["变量"];
Spdns~com
用超链接传送变量。
中国南通服务器网
如在任一页中建超链接:点击 中国.南通服务器网
在Edit.aspx页中取值:String str=Request.QueryString["fdid"];
南通服务器网
12、DOC对象.CreateElement("新建节点名");
Spdns_com
创建XML文档新节点 Www~Spdns~com
13、父节点.AppendChild(子节点); 南通服务器网
将新建的子节点加到XML文档父节点下
Www~Spdns~com
14、 父节点.RemoveChild(节点); Www~Spdns~com
删除节点
Spdns@com
15、Response
Spdns.com
Response.Write("字串");
中国南通服务器网
Response.Write(变量);
Spdns.com
向页面输出。 Spdns~com
Response.Redirect("URL地址");
中.国南通服务器网
跳转到URL指定的页面 Www^Spdns^com
16、char.IsWhiteSpce(字串变量,位数)——逻辑型
中.国.南通服务器网
查指定位置是否空字符;
Spdns~com
如:
中国南通服务器网
string str="中国 人民"; [南通服务器网]
Response.Write(char.IsWhiteSpace(str,2)); //结果为:True, 第一个字符是0位,2是第三个字符。 Spdns_com
17、char.IsPunctuation('字符') --逻辑型
Spdns_com
查字符是否是标点符号 中国南通服务器网
如:Response.Write(char.IsPunctuation('A')); //返回:False
中.国南通服务器网
18、(int)'字符' 南通服务器网
把字符转为数字,查代码点,注意是单引号。 中.国.南通服务器网
如:
中国南通服务器网
Response.Write((int)'中'); //结果为中字的代码:20013
Www@Spdns@com
19、(char)代码
Www^Spdns^com
把数字转为字符,查代码代表的字符。 Www.Spdns.com
如:
Www_Spdns_com
Response.Write((char)22269); //返回“国”字。 Www^Spdns^com
20、 Trim() Spdns
清除字串前后空格
Www~Spdns~com
21 、字串变量.Replace("子字串","替换为")
南通服务器网
字串替换 中.国.南通服务器网
如: Spdns.com
string str="中国";
Www_Spdns_com
str=str.Replace("国","央"); //将国字换为央字
Spdns
Response.Write(str); //输出结果为“中央”
中.国南通服务器网
再如:(这个非常实用)
Spdns