1、datetime 數(shù)字型
system.datetime currenttime=new system.datetime();
1.1 取當(dāng)前年月日時(shí)分秒
currenttime=system.datetime.now;
1.2 取當(dāng)前年
int 年=currenttime.year;
1.3 取當(dāng)前月
int 月=currenttime.month;
1.4 取當(dāng)前日
int 日=currenttime.day;
1.5 取當(dāng)前時(shí)
int 時(shí)=currenttime.hour;
1.6 取當(dāng)前分
int 分=currenttime.minute;
1.7 取當(dāng)前秒
int 秒=currenttime.second;
1.8 取當(dāng)前毫秒
int 毫秒=currenttime.millisecond;
(變量可用中文)
2、int32.parse(變量) int32.parse("常量")
字符型轉(zhuǎn)換 轉(zhuǎn)為32位數(shù)字型
3、 變量.tostring()
字符型轉(zhuǎn)換 轉(zhuǎn)為字符串
12345.tostring("n"); //生成 12,345.00
12345.tostring("c"); //生成 ¥12,345.00
12345.tostring("e"); //生成 1.234500e+004
12345.tostring("f4"); //生成 12345.0000
12345.tostring("x"); //生成 3039 (16進(jìn)制)
12345.tostring("p"); //生成 1,234,500.00%
4、變量.length 數(shù)字型
取字串長(zhǎng)度:
如: string str="中國(guó)";
int len = str.length ; //len是自定義變量, str是求測(cè)的字串的變量名
5、system.text.encoding.default.getbytes(變量)
字碼轉(zhuǎn)換 轉(zhuǎn)為比特碼
如:byte[] bytstr = system.text.encoding.default.getbytes(str);
然后可得到比特長(zhǎng)度:
len = bytstr.length;
6、system.text.stringbuilder("")
字符串相加,(+號(hào)是不是也一樣?)
如:system.text.stringbuilder sb = new system.text.stringbuilder("");
sb.append("中華");
sb.append("人民");
sb.append("共和國(guó)");
7、變量.substring(參數(shù)1,參數(shù)2);
截取字串的一部分,參數(shù)1為左起始位數(shù),參數(shù)2為截取幾位。
如:string s1 = str.substring(0,2);
8、string user_ip=request.servervariables["remote_addr"].tostring();
取遠(yuǎn)程用戶(hù)ip地址
9、穿過(guò)代理服務(wù)器取遠(yuǎn)程用戶(hù)真實(shí)ip地址:
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();
}
10、 session["變量"];
存取session值;
如,賦值: session["username"]="小布什";
取值: object objname=session["username"];
string strname=objname.tostring();
清空: session.removeall();
11、string str=request.querystring["變量"];
用超鏈接傳送變量。
如在任一頁(yè)中建超鏈接:<a href=edit.aspx?fbid=23>點(diǎn)擊</a>
在edit.aspx頁(yè)中取值:string str=request.querystring["fdid"];
12、doc對(duì)象.createelement("新建節(jié)點(diǎn)名");
創(chuàng)建xml文檔新節(jié)點(diǎn)
13、父節(jié)點(diǎn).appendchild(子節(jié)點(diǎn));
將新建的子節(jié)點(diǎn)加到xml文檔父節(jié)點(diǎn)下
14、 父節(jié)點(diǎn).removechild(節(jié)點(diǎn));
刪除節(jié)點(diǎn)
15、response
response.write("字串");
response.write(變量);
向頁(yè)面輸出。
response.redirect("url地址");
跳轉(zhuǎn)到url指定的頁(yè)面
16、char.iswhitespce(字串變量,位數(shù))——邏輯型
查指定位置是否空字符;
如:
string str="中國(guó) 人民";
response.write(char.iswhitespace(str,2)); //結(jié)果為:true, 第一個(gè)字符是0位,2是第三個(gè)字符。
17、char.ispunctuation('字符') --邏輯型
查字符是否是標(biāo)點(diǎn)符號(hào)
如:response.write(char.ispunctuation('a')); //返回:false
18、(int)'字符'
把字符轉(zhuǎn)為數(shù)字,查代碼點(diǎn),注意是單引號(hào)。
如:
response.write((int)'中'); //結(jié)果為中字的代碼:20013
19、(char)代碼
把數(shù)字轉(zhuǎn)為字符,查代碼代表的字符。
如:
response.write((char)22269); //返回“國(guó)”字。
20、 trim()
清除字串前后空格
21 、字串變量.replace("子字串","替換為")
字串替換
如:
string str="中國(guó)";
str=str.replace("國(guó)","央"); //將國(guó)字換為央字
response.write(str); //輸出結(jié)果為“中央”
再如:(這個(gè)非常實(shí)用)
string str="這是<script>腳本";
str=str.replace("<","<font><</font>"); //將左尖括號(hào)替換為<font> 與 < 與 </font> (或換為<,但估計(jì)經(jīng)xml存諸后,再提出仍會(huì)還原)
response.write(str); //顯示為:“這是<script>腳本”
如果不替換,<script>將不顯示,如果是一段腳本,將運(yùn)行;而替換后,腳本將不運(yùn)行。
這段代碼的價(jià)值在于:你可以讓一個(gè)文本中的所有html標(biāo)簽失效,全部顯示出來(lái),保護(hù)你的具有交互性的站點(diǎn)。
具體實(shí)現(xiàn):將你的表單提交按鈕腳本加上下面代碼:
string strsubmit=label1.text; //label1是你讓用戶(hù)提交數(shù)據(jù)的控件id。
strsubmit=strsubmit.replace("<","<font><</font>");
然后保存或輸出strsubmit。
用此方法還可以簡(jiǎn)單實(shí)現(xiàn)ubb代碼。
22、math.max(i,j)
取i與j中的最大值
如 int x=math.max(5,10); // x將取值 10
新聞熱點(diǎn)
疑難解答
圖片精選