C 常用函式及方法集

2021-04-09 01:20:51 字數 2585 閱讀 3531

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 =

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="這是指令碼";  

str=str.replace("<","<");  //將左尖括號替換為與 < 與  (或換為<,但估計經xml存諸后,再提出仍會還原)  

response.write(str); //顯示為:「這是指令碼」  

如果不替換,將不顯示,如果是一段指令碼,將執行;而替換後,指令碼將不執行。  

這段**的價值在於:你可以讓乙個文字中的所有html標籤失效,全部顯示出來,保護你的具有互動性

的站點。  

具體實現:將你的表單提交按鈕指令碼加上下面**:  

string strsubmit=label1.text;   //label1是你讓使用者提交資料的控制項id。  

strsubmit=strsubmit.replace("<","<");   

然後儲存或輸出strsubmit。  

用此方法還可以簡單實現ubb**。  

22、math.max(i,j)  

取i與j中的最大值  

如 int x=math.max(5,10);  // x將取值 10

C 常用函式和方法集

1 datetime 數字型 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.now 1.2 取當前年 int 年 currenttime.year 1.3 取當前月 ...

彙總c 常用函式和方法集

彙總c 常用函式和方法集 3 變數.tostring 字元型轉換 轉為字串 12345.tostring n 生成 12,345.00 12345.tostring c 生成 12,345.00 12345.tostring e 生成 1.234500e 004 12345.tostring f4 ...

C 常用函式和方法集彙總

1 datetime 數字型 system.datetime currenttime new system.datetime 1.1 取當前年月日時分秒 currenttime system.datetime.now 1.2 取當前年 int 年 currenttime.year 1.3 取當前月 ...