国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.Net函數集

2024-07-10 13:09:03
字體:
來源:轉載
供稿:網友

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;
(變量可用中文)

2、int32.parse(變量) int32.parse("常量")
字符型轉換 轉為32位數字型

3、 變量.tostring()
字符型轉換 轉為字符串
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進制)
12345.tostring("p"); //生成 1,234,500.00%

4、變量.length 數字型
取字串長度:
如: string str="中國";
int len = str.length ; //len是自定義變量, str是求測的字串的變量名

5、system.text.encoding.default.getbytes(變量)
字碼轉換 轉為比特碼
如:byte[] bytstr = system.text.encoding.default.getbytes(str);
然后可得到比特長度:
len = bytstr.length;

6、system.text.stringbuilder("")
字符串相加,(+號是不是也一樣?)
如:system.text.stringbuilder sb = new system.text.stringbuilder("");
sb.append("中華");
sb.append("人民");
sb.append("共和國");

7、變量.substring(參數1,參數2);
截取字串的一部分,參數1為左起始位數,參數2為截取幾位。
如:string s1 = str.substring(0,2);

8、string user_ip=request.servervariables["remote_addr"].tostring();
取遠程用戶ip地址

9、穿過代理服務器取遠程用戶真實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["變量"];
用超鏈接傳送變量。
如在任一頁中建超鏈接:<a href=edit.aspx?fbid=23>點擊</a>
在edit.aspx頁中取值:string str=request.querystring["fdid"];

12、doc對象.createelement("新建節點名");
創建xml文檔新節點

13、父節點.appendchild(子節點);
將新建的子節點加到xml文檔父節點下

14、 父節點.removechild(節點);
刪除節點

15、response
response.write("字串");
response.write(變量);
向頁面輸出。

response.redirect("url地址");
跳轉到url指定的頁面

16、char.iswhitespce(字串變量,位數)——邏輯型
查指定位置是否空字符;
如:
string str="中國 人民";
response.write(char.iswhitespace(str,2)); //結果為:true, 第一個字符是0位,2是第三個字符。

17、char.ispunctuation('字符') --邏輯型
查字符是否是標點符號
如:response.write(char.ispunctuation('a')); //返回:false

18、(int)'字符'
把字符轉為數字,查代碼點,注意是單引號。
如:
response.write((int)'中'); //結果為中字的代碼:20013

19、(char)代碼
把數字轉為字符,查代碼代表的字符。
如:
response.write((char)22269); //返回“國”字。

20、 trim()
清除字串前后空格

21 、字串變量.replace("子字串","替換為")
字串替換
如:
string str="中國";
str=str.replace("國","央"); //將國字換為央字
response.write(str); //輸出結果為“中央”

再如:(這個非常實用)

string str="這是<script>腳本";
str=str.replace("<","<font><</font>"); //將左尖括號替換為<font> 與 < 與 </font> (或換為<,但估計經xml存諸后,再提出仍會還原)
response.write(str); //顯示為:“這是<script>腳本”

如果不替換,<script>將不顯示,如果是一段腳本,將運行;而替換后,腳本將不運行。
這段代碼的價值在于:你可以讓一個文本中的所有html標簽失效,全部顯示出來,保護你的具有交互性的站點。
具體實現:將你的表單提交按鈕腳本加上下面代碼:
string strsubmit=label1.text; //label1是你讓用戶提交數據的控件id。
strsubmit=strsubmit.replace("<","<font><</font>");
然后保存或輸出strsubmit。
用此方法還可以簡單實現ubb代碼。

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");
'www.knowsky.com
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);

2、int32.parse(變量) int32.parse("常量")
字符型轉換 轉為32位數字型

3、 變量.tostring()
字符型轉換 轉為字符串
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進制)
12345.tostring("p"); //生成 1,234,500.00%

4、變量.length 數字型
取字串長度:
如: string str="中國";
int len = str.length ; //len是自定義變量, str是求測的字串的變量名

5、system.text.encoding.default.getbytes(變量)
字碼轉換 轉為比特碼
如:byte[] bytstr = system.text.encoding.default.getbytes(str);
然后可得到比特長度:
len = bytstr.length;

6、system.text.stringbuilder("")
字符串相加,(+號是不是也一樣?)
如:system.text.stringbuilder sb = new system.text.stringbuilder("");
sb.append("中華");
sb.append("人民");
sb.append("共和國");

7、變量.substring(參數1,參數2);
截取字串的一部分,參數1為左起始位數,參數2為截取幾位。
如:string s1 = str.substring(0,2);

8、string user_ip=request.servervariables["remote_addr"].tostring();
取遠程用戶ip地址

9、穿過代理服務器取遠程用戶真實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["變量"];
用超鏈接傳送變量。
如在任一頁中建超鏈接:<a href=edit.aspx?fbid=23>點擊</a>
在edit.aspx頁中取值:string str=request.querystring["fdid"];

12、doc對象.createelement("新建節點名");
創建xml文檔新節點

13、父節點.appendchild(子節點);
將新建的子節點加到xml文檔父節點下

14、 父節點.removechild(節點);
刪除節點

15、response
response.write("字串");
response.write(變量);
向頁面輸出。

response.redirect("url地址");
跳轉到url指定的頁面

16、char.iswhitespce(字串變量,位數)——邏輯型
查指定位置是否空字符;
如:
string str="中國 人民";
response.write(char.iswhitespace(str,2)); //結果為:true, 第一個字符是0位,2是第三個字符。

17、char.ispunctuation('字符') --邏輯型
查字符是否是標點符號
如:response.write(char.ispunctuation('a')); //返回:false

18、(int)'字符'
把字符轉為數字,查代碼點,注意是單引號。
如:
response.write((int)'中'); //結果為中字的代碼:20013

19、(char)代碼
把數字轉為字符,查代碼代表的字符。
如:
response.write((char)22269); //返回“國”字。

20、 trim()
清除字串前后空格

21 、字串變量.replace("子字串","替換為")
字串替換
如:
string str="中國";
str=str.replace("國","央"); //將國字換為央字
response.write(str); //輸出結果為“中央”

再如:(這個非常實用)

string str="這是<script>腳本";
str=str.replace("<","<font><</font>"); //將左尖括號替換為<font> 與 < 與 </font> (或換為<,但估計經xml存諸后,再提出仍會還原)
response.write(str); //顯示為:“這是<script>腳本”

如果不替換,<script>將不顯示,如果是一段腳本,將運行;而替換后,腳本將不運行。
這段代碼的價值在于:你可以讓一個文本中的所有html標簽失效,全部顯示出來,保護你的具有交互性的站點。
具體實現:將你的表單提交按鈕腳本加上下面代碼:
string strsubmit=label1.text; //label1是你讓用戶提交數據的控件id。
strsubmit=strsubmit.replace("<","<font><</font>");
然后保存或輸出strsubmit。
用此方法還可以簡單實現ubb代碼。

22、math.max(i,j)
取i與j中的最大值
如 int x=math.max(5,10); // x將取值 10

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()
從指定位置開始刪除指定數的字符
<%
string str1="我是薩達姆的崇拜者之一";
response.write(str1.remove(5,4)); //結果為“我是薩達姆之一”
%>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 溆浦县| 铜川市| 依兰县| 大同市| 华容县| 福安市| 乌拉特中旗| 陆川县| 新巴尔虎左旗| 赤城县| 义马市| 永靖县| 交城县| 山东省| 定安县| 娄底市| 永川市| 新泰市| 龙井市| 漠河县| 大田县| 鹤岗市| 江油市| 抚顺市| 汕头市| 年辖:市辖区| 汉川市| 西青区| 平舆县| 全州县| 类乌齐县| 承德县| 平塘县| 麟游县| 三亚市| 温泉县| 萍乡市| 轮台县| 桂阳县| 军事| 宽甸|