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["變數"];
以下是引用片段:
用超鏈結傳送變數。
如在任一頁中建超鏈結:點擊
在Edit.aspx頁中取值:String str=Request.QueryString["fdid"];
12、DOC對象.CreateElement("新建節點名");
以下是引用片段:
創建XML文檔新節點
13、父節點.AppendChild(子節點);
以下是引用片段:
將新建的子節點加到XML文檔父節點下
14、 父節點.RemoveChild(節點);
以下是引用片段:
刪除節點
1
2
下一頁>>