Visual C 常用函式和方法集彙總

2021-04-21 22:03:44 字數 3076 閱讀 6032

1.字元型轉換 轉為32位數字型

int32.parse(變數) int32.parse("常量")

2.變數.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%

3.變數.length 數字型

取字串長度:

如: string str="中國";

int len = str.length ; //len是自定義變數, str是求測的字串的變數名

4.字碼轉換 轉為比**

system.text.encoding.default.getbytes(變數)      //在加密欄位是長用到

如:byte bytstr = system.text.encoding.default.getbytes(str);

然後可得到位元長度:

len = bytstr.length;

5.system.text.stringbuilder("")

字串相加,(+號是不是也一樣?)

如: 擷取字串的一部分,引數1為左起始位數,引數2為擷取幾位。

如:string s1 = str.substring(0,2);

7.取遠端使用者ip位址

9.訪問session值

session["變數"];

如,賦值:

session["username"]="小泉";

取值:

object objname=session["username"];

string strname=objname.tostring();

清空:

在edit.aspx頁中取值:string str=request.querystring["fdid"];

11、建立xml文件新節點   //你先要申明乙個xmldoc物件

doc物件.createelement("新建節點名");

12、將新建的子節點加到xml文件父節點下

13、 刪除節點

父節點.removechild(節點);

14、向頁面輸出:response

response.write("字串");

response.write(變數);

跳轉到url指定的頁面:

response.redirect("url位址");

15、查指定位置是否空字元

char.iswhitespce(字串變數,位數)——邏輯型;   

如: string str="中國 人民";

response.write(char.iswhitespace(str,2)); //結果為:true, 第乙個字元是0位,2是第三個字元。

16、查字元是否是標點符號

char.ispunctuation(''字元'') --邏輯型

如: response.write(char.ispunctuation(''a'')); //返回:false

17、把字元轉為數字,查**點,注意是單引號。

(int)''字元''

如: response.write((int)''中''); //結果為中字的**:20013

18、把數字轉為字元,查**代表的字元:(char)**

如: response.write((char)22269); //返回「國」字。

19、 清除字串前後空格: trim()

string str="     fsdf    ";

str=str.trim(); //可以清楚了

20.datetime 數字型       // 時間型別的是最不好控制但是又是到處都要用到的,在具體的與各種資料庫的時間型別的對應中還有更大的問題,有時的處理就乾脆儲存為string

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 取當前年月日,格式為:2003-9-23

string strymd=currenttime.tostring("d");

1.13 取當前時分,格式為:14:24

string strt=currenttime.tostring("t");

Visual C 常用函式和方法集彙總

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

Visual C 常用函式和方法集彙總

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

Visual C 常用函式和方法集彙總

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