惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
V
V2EX
博客园_首页
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
H
Help Net Security
A
About on SuperTechFans
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
云风的 BLOG
云风的 BLOG
D
Docker
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
A
Arctic Wolf
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
T
Troy Hunt's Blog
T
Tenable Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Recorded Future
Recorded Future
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog
T
Threat Research - Cisco Blogs
MyScale Blog
MyScale Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence

博客园 - TomSun

sql语句优化 页面生存周期 SQL Server 存储过程的分页 利用鼠标中键缩放图片 - TomSun - 博客园 不间断连续图片滚动效果的制作方法 - TomSun - 博客园 IE问题解决方法汇总 Calendar的相关问题. 无法打开注册表关键字错误----修改方法 N级无刷新连动菜单 - TomSun - 博客园 JScript中正则表达函数的说明与应用 正则表达式语法 ASP生成柱型体,折线图,饼图源代码 - TomSun - 博客园 ASP必读[常见问题集] 常用SQL语句(不断更新) Javascript里类的思想(zz) - TomSun - 博客园 JS写的Cookie类 ASP调用系统ping命令 XMLHTTP---介绍 ASP.net 验证码(C#)
c#.net常用的小函数和方法集
TomSun · 2005-08-05 · via 博客园 - TomSun

Posted on 2005-08-05 09:11  TomSun  阅读(516)  评论()    收藏  举报

  11、DateTime 数字型 
  2System.DateTime currentTime=new System.DateTime(); 
  31.1 取当前年月日时分秒 
  4currentTime=System.DateTime.Now; 
  51.2 取当前年 
  6int 年=currentTime.Year; 
  71.3 取当前月 
  8int 月=currentTime.Month; 
  91.4 取当前日 
 10int 日=currentTime.Day; 
 111.5 取当前时 
 12int 时=currentTime.Hour; 
 131.6 取当前分 
 14int 分=currentTime.Minute; 
 151.7 取当前秒 
 16int 秒=currentTime.Second; 
 171.8 取当前毫秒 
 18int 毫秒=currentTime.Millisecond; 
 19(变量可用中文) 
 20
 212、Int32.Parse(变量) Int32.Parse("常量"
 22字符型转换 转为32位数字型 
 23
 243、 变量.ToString() 
 25字符型转换 转为字符串 
 2612345.ToString("n"); //生成 12,345.00 
 2712345.ToString("C"); //生成 ¥12,345.00 
 2812345.ToString("e"); //生成 1.234500e+004 
 2912345.ToString("f4"); //生成 12345.0000 
 3012345.ToString("x"); //生成 3039 (16进制) 
 3112345.ToString("p"); //生成 1,234,500.00% 
 32
 33
 344、变量.Length 数字型 
 35取字串长度: 
 36如: string str="中国"
 37int Len = str.Length ; //Len是自定义变量, str是求测的字串的变量名 
 38
 395、System.Text.Encoding.Default.GetBytes(变量) 
 40字码转换 转为比特码 
 41如:byte[] bytStr = System.Text.Encoding.Default.GetBytes(str); 
 42然后可得到比特长度: 
 43len = bytStr.Length; 
 44
 456、System.Text.StringBuilder(""
 46字符串相加,(+号是不是也一样?) 
 47如:System.Text.StringBuilder sb = new System.Text.StringBuilder(""); 
 48sb.Append("中华"); 
 49sb.Append("人民"); 
 50sb.Append("共和国"); 
 51
 527、变量.Substring(参数1,参数2); 
 53截取字串的一部分,参数1为左起始位数,参数2为截取几位。 
 54如:string s1 = str.Substring(0,2); 
 55
 568、String user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString(); 
 57取远程用户IP地址 
 58
 599、穿过代理服务器取远程用户真实IP地址: 
 60if(Request.ServerVariables["HTTP_VIA"]!=null)
 61string user_IP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); 
 62}
else
 63string user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString(); 
 64}
 
 65
 6610、 Session["变量"]; 
 67存取Session值; 
 68如,赋值: Session["username"]="小布什"
 69
 70取值: Object objName=Session["username"]; 
 71String strName=objName.ToString(); 
 72清空: Session.RemoveAll(); 
 73
 7411、String str=Request.QueryString["变量"]; 
 75用超链接传送变量。 
 76如在任一页中建超链接:<a href=Edit.aspx?fbid=23>点击</a> 
 77在Edit.aspx页中取值:String str=Request.QueryString["fdid"]; 
 78
 7912、DOC对象.CreateElement("新建节点名"); 
 80创建XML文档新节点 
 81
 8213、父节点.AppendChild(子节点); 
 83将新建的子节点加到XML文档父节点下 
 84
 8514、 父节点.RemoveChild(节点); 
 86删除节点 
 87
 8815、Response 
 89Response.Write("字串"); 
 90Response.Write(变量); 
 91向页面输出。 
 92
 93Response.Redirect("URL地址"); 
 94跳转到URL指定的页面 
 95
 9616char.IsWhiteSpce(字串变量,位数)——逻辑型 
 97查指定位置是否空字符; 
 98如: 
 99string str="中国 人民"
100Response.Write(char.IsWhiteSpace(str,2)); //结果为:True, 第一个字符是0位,2是第三个字符。 
101
10217char.IsPunctuation('字符'--逻辑型 
103查字符是否是标点符号 
104如:Response.Write(char.IsPunctuation('A')); //返回:False 
105
10618、(int)'字符' 
107把字符转为数字,查代码点,注意是单引号。 
108如: 
109Response.Write((int)''); //结果为中字的代码:20013 
110
11119、(char)代码 
112把数字转为字符,查代码代表的字符。 
113如: 
114Response.Write((char)22269); //返回“国”字。 
115
11620、 Trim() 
117清除字串前后空格 
118
11921 、字串变量.Replace("子字串","替换为"
120字串替换 
121如: 
122string str="中国"
123str=str.Replace("",""); //将国字换为央字 
124Response.Write(str); //输出结果为“中央” 
125
126再如:(这个非常实用) 
127
128string str="这是<script>脚本"
129str=str.Replace("<","<font><</font>"); //将左尖括号替换为<font> 与 < 与 </font> (或换为&lt,但估计经XML存诸后,再提出仍会还原) 
130Response.Write(str); //显示为:“这是<script>脚本” 
131
132如果不替换,<script>将不显示,如果是一段脚本,将运行;而替换后,脚本将不运行。 
133这段代码的价值在于:你可以让一个文本中的所有HTML标签失效,全部显示出来,保护你的具有交互性的站点。 
134具体实现:将你的表单提交按钮脚本加上下面代码: 
135string strSubmit=label1.Text; //label1是你让用户提交数据的控件ID。 
136strSubmit=strSubmit.Replace("<","<font><</font>"); 
137然后保存或输出strSubmit。 
138用此方法还可以简单实现UBB代码。 
139
14022、Math.Max(i,j) 
141取i与j中的最大值 
142如 int x=Math.Max(5,10); // x将取值 10