首页  新闻  文章  软件  动画  编程  设计  视频  搜黑  网址  网校  博客  论坛  邮箱  最近更新

漏洞公布  病毒公告  业界动态  黑客新闻  黑客人物  杀毒防护  安全书籍  升级补丁
入侵检测  漏洞研究  软件评测  操作系统  技巧知识  网管天地  黑客编程  Q Q 技巧  安全防护
扫描检测  远程监控  脚本注入  拒绝攻击  嗅探监听  木马后门  字典代理  密码破解  Q Q 软件
Q Q 动画  木马教程  脚本入侵  漏洞利用  加密破解  软件应用  安全配置  综合教程
Delphi编程  汇编编程  VB编程  VC/C++编程  PB编程  VFP编程  WEB编程  Exploite  数据库编程
黑客培训 2G防毒Email
·搜黑-全球首例黑客资讯搜索
·视频-国内视频学习教学大全
·设计-汇集百家设计网站精华
·编程-13大编程语言全面学习
安全中国首页 > 编程中心 > ASP编程
ASP实用函数库
http://www.anqn.com       时间:2005-9-1 19:12:00       责任编辑:王奇       网友评论 
热 点:
<%
'判断文件名是否合法
Function isFilename(aFilename)
 Dim sErrorStr,iNameLength,i
 isFilename=TRUE
 sErrorStr=Array("/","\",":","*","?","""","<",">","|")
 iNameLength=Len(aFilename)
 If iNameLength<1 Or iNameLength=null Then
  isFilename=FALSE
 Else
  For i=0 To 8
   If instr(aFilename,sErrorStr(i)) Then
    isFilename=FALSE    
   End If
  Next
 End If
End Function

'去掉字符串头尾的连续的回车和空格
function trimVBcrlf(str)
 trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))
end function

'去掉字符串开头的连续的回车和空格
function ltrimVBcrlf(str)
 dim pos,isBlankChar
 pos=1
 isBlankChar=true
 while isBlankChar
  if mid(str,pos,1)=" " then
   pos=pos+1
  elseif mid(str,pos,2)=VBcrlf then
   pos=pos+2
  else
   isBlankChar=false
  end if
 wend
 ltrimVBcrlf=right(str,len(str)-pos+1)
end function

'去掉字符串末尾的连续的回车和空格
function rtrimVBcrlf(str)
 dim pos,isBlankChar
 pos=len(str)
 isBlankChar=true
 while isBlankChar and pos>=2
  if mid(str,pos,1)=" " then
   pos=pos-1
  elseif mid(str,pos-1,2)=VBcrlf then
   pos=pos-2
  else
   isBlankChar=false
  end if
 wend
 rtrimVBcrlf=rtrim(left(str,pos))
end function

'判断Email是否有效,返回1表示正确
Function isEmail(aEmail)
 Dim iLocat,v,iLength,i,checkletter
 If instr(aEmail,"@") = 0 Or instr(aEmail,".") = 0 Then
  isEmail=0
  EXIT FUNCTION
 End If
 iLocat=instr(aEmail,"@")
 If instr(iLocat,aEmail,".")=0 Or instr(iLocat+1,aEmail,"@")>0 Then
  isEmail=0
  EXIT FUNCTION
 End If
 If left(aEmail,1)="." Or right(aEmail,1)="." Or left(aEmail,1)="@" Or right(aEmail,1)="@" Then
  isEmail=0
  EXIT FUNCTION
 End If
 v="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@"
 iLength=len(aEmail)
 For i=1 To iLength
  checkletter=mid(aEmail,i,1)
  If instr(v,checkletter)=0 Then
   isEmail=0
   EXIT FUNCTION
  End If
 Next
 isEmail=1
End Function

'测试用:显示服务器信息
Sub showServer
 Dim name
 Response.write "<Table border=1 bordercolor=lightblue CELLSPACING=0>"
 for each name in request.servervariables
  Response.write "<tr>"
  Response.write "<td>"&name&"</td>"
  Response.write "<td>"&request.servervariables(name)&"<br></td>"
  Response.write "</tr>"
 next
 Response.write "</table>"
End Sub

'测试用:显示Rs结果集以及字段名称
Sub showRs(rs)
 Dim strTable,whatever
 Response.write "<center><table><tr>"
 for each whatever in rs.fields
  response.write "<td><b>" & whatever.name & "</B></TD>"
 next
 strTable = "</tr><tr><td>"&rs.GetString(,,"</td><td>","</tr><tr><td>"," ") &"</td></tr></table></center>"
 Response.Write(strTable)
End Sub

'用HTML格式显示文本
Function txt2Html(str)
 if isnull(str) then
  txt2Html=""
  exit Function
 end if
 str=Replace(str,chr(34),""")
 str=Replace(str,"<","<")
 str=Replace(str,">",">")
 str=Replace(str,chr(13)+chr(10),"<br>")
 str=Replace(str,chr(9),"    ")
 str=Replace(str," "," ")
 txt2Html=str
End Function

'测试用:显示调试错误信息
Sub showError
 Dim sErrMsg
 sErrMsg=Err.Source&" "&Err.Description
 Response.write "<center>"&sErrMsg&"</center>"
 Err.clear
End Sub

'显示文字计数器
Sub showCounter
Dim fs,outfile,filename,count
filename=server.mappath("count.txt")
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileExists(filename) Then
 Set outfile=fs.openTextFile(filename,1)
 count=outfile.readline
 count=count+1
 Response.write "<center>浏览人次:"&count&"<center>"
 outfile.close
 Set outfile=fs.CreateTextFile(filename)
 outfile.writeline(count)
Else
 Set outfile=fs.openTextFile(filename,8,TRUE)
 count=0
 outfile.writeline(count)
END IF
outfile.close
set fs=nothing
End Sub
%>

Array() 
 FUNCTION: 返回一个数组 
 SYNTAX: Array(list) 
 ARGUMENTS: 字符,数字均可 
 EXAMPLE: <%
Dim myArray()
For i = 1 to 7
  Redim Preserve myArray(i)
  myArray(i) = WeekdayName(i)
Next
%> 
 RESULT: 建立了一个包含7个元素的数组myArray
myArray("Sunday","Monday", ... ... "Saturday") 
 
CInt() 
 FUNCTION: 将一个表达式转化为数字类型 
 SYNTAX: CInt(expression) 
 ARGUMENTS: 任何有效的字符均可 
 EXAMPLE: <%
f = "234"
response.write cINT(f) + 2
%> 
 RESULT: 236
转化字符"234"为数字"234",如果字符串为空,则返回0值  
 
CreateObject() 
 FUNCTION: 建立和返回一个已注册的ACTIVEX组件的实例。 
 SYNTAX: CreateObject(objName) 
 ARGUMENTS: objName 是任何一个有效、已注册的ACTIVEX组件的名字. 
 EXAMPLE: <%
Set con = Server.CreateObject("ADODB.Connection")
%> 
 RESULT: 
 
CStr() 
 FUNCTION: 转化一个表达式为字符串. 
 SYNTAX: CStr(expression) 
 ARGUMENTS: expression 是任何有效的表达式。 
 EXAMPLE: <%
s = 3 + 2
response.write "The result is: " & cStr(s)
%> 
 RESULT: 转化数字“5”为字符“5”。 
 
Date() 
 FUNCTION: 返回当前系统日期. 
 SYNTAX: Date() 
 ARGUMENTS: None. 
 EXAMPLE: <%=Date%> 
 RESULT: 8/4/99 
 
DateAdd() 
 FUNCTION: 返回一个被改变了的日期。 
 SYNTAX: DateAdd(timeinterval,number,date) 
 ARGUMENTS: timeinterval is the time interval to add; number is amount of 
time intervals to add; and date is the starting date. 
 EXAMPLE: <%
currentDate = #8/4/99#
newDate = DateAdd("m",3,currentDate)
response.write newDate
%>

<%
currentDate = #12:34:45 PM#
newDate = DateAdd("h",3,currentDate)
response.write newDate
%> 
 RESULT: 11/4/99
3:34:45 PM

"m" = "month";
"d" = "day";

If currentDate is in time format then,
"h" = "hour"; 
"s" = "second"; 
 
DateDiff() 
 FUNCTION: 返回两个日期之间的差值 。 
 SYNTAX: DateDiff(timeinterval,date1,date2 [, firstdayofweek ][, 
firstweekofyear]]) 
 ARGUMENTS: timeinterval 表示相隔时间的类型,如“M“表示“月”。 
 EXAMPLE: <%
fromDate = #8/4/99#
toDate = #1/1/2000#
response.write "There are " & _
  DateDiff("d",fromDate,toDate) & _
  " days to millenium from 8/4/99."
%> 
 RESULT: 从8/4/99 到2000年还有 150 天. 
 
Day() 
 FUNCTION: 返回一个月的第几日 . 
 SYNTAX: Day(date) 
 ARGUMENTS: date 是任何有效的日期。 
 EXAMPLE: <%=Day(#8/4/99#)%> 
 RESULT: 4 
 
FormatCurrency() 
 FUNCTION: 返回表达式,此表达式已被格式化为货币值  
 SYNTAX: FormatCurrency(Expression [, Digit ][, LeadingDigit ][, Paren ][, 
GroupDigit]]]]) 
 ARGUMENTS: Digit 指示小数点右侧显示位数的数值。默认值为 -1,指示使用的是
计算机的区域设置; LeadingDigit 三态常数,指示是否显示小数值小数点前面的
零。 

[1] [2] [3] 下一页

·上一篇: ASP操作Excel技术总结
·下一篇:跟我学小偷程序之几个基本函数(第二天)

发表评论  打印本文  返回顶部  关闭窗口
最新5条评论 条评论
条评论
名称: 信箱:

相关连接
·跟我学小偷程序教程之小偷原理(第一天) [2005-9-1]
·跟我学小偷程序之几个基本函数(第二天) [2005-9-1]
·ASP操作Excel技术总结 [2005-9-1]
·不刷新页面的情况下调用ASP [2005-9-1]
·用ASP建立自己网站的每日更新 [2005-9-1]
·商业网站应用设计 [2005-9-1]
·ASP的错误处理 [2005-9-1]
·利用ASP+JMAIL进行邮件群发的新思路 [2005-9-1]
·用ASPJPEG组件制作图片的缩略图和加水印 [2005-9-1]
·如何利用ASP实现邮箱访问 [2005-9-1]