asp字符串处理通用函数

合集下载

asp的常用函数用法

asp的常用函数用法

asp的常用函数用法关于asp 的常用函数用法Array()FUNCTION:返回一个数组SYNTAX:Array(list)ARGUMENTS:字符,数字均可EXAMPLE:<%DimmyArray()Fori=1to7RedimPreservemyArray(i)myArray(i)=WeekdayName(i)Next%>RESULT:建立了一个包含7个元素的数组myArraymyArray("Sunday","Monday",......"Saturday")CInt()FUNCTION:将一个表达式转化为数字类型SYNTAX:CInt(expression)ARGUMENTS:任何有效的字符均可EXAMPLE:<%f="234"response.writecINT(f)+2%>RESULT:236转化字符"234"为数字"234",如果字符串为空,则返回0值CreateObject()FUNCTION:建立和返回一个已注册的ACTIVEX组件的实例。

SYNTAX:CreateObject(objName)ARGUMENTS:objName是任何一个有效、已注册的ACTIVEX组件的名字.EXAMPLE:<%Setcon=Server.CreateObject("ADODB.Connection")%>RESULT:CStr()FUNCTION:转化一个表达式为字符串.SYNTAX:CStr(expression)ARGUMENTS:expression是任何有效的表达式。

EXAMPLE:<%s=3+2response.write"Theresultis:"&cStr(s)%>RESULT:转化数字“5”为字符“5”。

php常用字符串函数_asp常用的字符串处理函数

php常用字符串函数_asp常用的字符串处理函数

Cla Cl_Fun Private 某,y,ii ============================== 函数名:AlertInfo 作用:错误显示函数参数:错误提示内容InfoStr,转向页面GoUrl ============================== Public FunctionAlertInfo(InfoStr,GoUrl) If GoUrl="1" Then Repone.Write "<Script>alert(""& InfoStr &"");location.href="javacript:hitory.go(-1)";</Script>" Ele Repone.Write"<Script>alert(""& InfoStr &"");location.href=""& GoUrl &"";</Script>" EndIf Repone.End() End Function ============================== 函数名:HTMLEncode 作用:字符转换函数参数:需要转换的文本fString ============================================================ 函数名:AlertNum 作用:判断是否是数字(验证字符,不为数字时的提示)参数:需进行判断的文本CheckStr,错误提示ErrStr ============================== Public FunctionAlertNum(CheckStr,ErrStr) If Not INumeric(CheckStr) or CheckStr="" Then Call AlertInfo(ErrStr,"1") End If End Function============================== 函数名:AlertString 作用:判断字符串长度参数:需进行判断的文本CheckStr 限定最短ShortLen 限定最长LongLen验证类型CheckType(0两头限制,1限制最短,2限制最长)过短提示LongStr 过长提示LongStr, ============================== Public Function AlertString(CheckStr,ShortLen,LongLen,CheckType,ShortErr,LongErr) If (CheckType=0 Or CheckType=1) And StringLength(CheckStr)<ShortLen Then Call AlertInfo(ShortStr,"1") End If If (CheckType=0 Or CheckType=2) And StringLength(CheckStr)>LongLen Then Call AlertInfo(LongStr,"1") End If End Function ============================== 函数名:AlertNum 作用:判断是否是数字(验证字符,不为数字时的提示)参数:需进行判断的文本CheckStr,错误提示ErrStr ============================== Public FunctionShowNum(CheckStr,ErrStr) If Not INumeric(CheckStr) or CheckStr=""Then Repone.Write(ErrStr&"|||||") PageErr=1 End If End Function============================== 函数名:ShowString 作用:判断字符串长度参数:需进行判断的文本CheckStr 限定最短ShortLen 限定最长LongLen 验证类型CheckType(0两头限制,1限制最短,2限制最长)过短提示LongStr 过长提示LongStr, ============================== Public Function ShowString(CheckStr,ShortLen,LongLen,CheckType,ShortErr,LongErr) If (CheckType=0 Or CheckType=1) And StringLength(CheckStr)<ShortLenThen Repone.Write(ShortErr&"|||||") PageErr=1 End If If (CheckType=0 Or CheckType=2) And StringLength(CheckStr)>LongLenThen Repone.Write(LongErr&"|||||") PageErr=1 End If EndFunction a ============================== 函数名:BeSelect 作用:判断elect选项选中参数:Select1,Select2 ============================== Public Function BeSelect(Select1,Select2) If Select1=Select2 Then BeSelect="elected="elected"" End If End Function ============================== 函数名:BeCheck 作用:判断Check选项选中参数:Check1,Check2 ============================== Public Function BeCheck(Check1,Check2) If Check1=Check2 Then BeCheck=" checked="checked"" End If End Function。

ASP常用函数:getpy()

ASP常用函数:getpy()

ASP常⽤函数:getpy()<%'取字段数据每个汉字的拼⾳⾸字母Function getpychar(char)tmp = 65536 + Asc(char)If(tmp>= 45217 And tmp<= 45252) Thengetpychar = "A"ElseIf(tmp>= 45253 And tmp<= 45760) Thengetpychar = "B"ElseIf(tmp>= 47761 And tmp<= 46317) Thengetpychar = "C"ElseIf(tmp>= 46318 And tmp<= 46825) Thengetpychar = "D"ElseIf(tmp>= 46826 And tmp<= 47009) Thengetpychar = "E"ElseIf(tmp>= 47010 And tmp<= 47296) Thengetpychar = "F"ElseIf(tmp>= 47297 And tmp<= 47613) Thengetpychar = "G"ElseIf(tmp>= 47614 And tmp<= 48118) Thengetpychar = "H"ElseIf(tmp>= 48119 And tmp<= 49061) Thengetpychar = "J"ElseIf(tmp>= 49062 And tmp<= 49323) Thengetpychar = "K"ElseIf(tmp>= 49324 And tmp<= 49895) Thengetpychar = "L"ElseIf(tmp>= 49896 And tmp<= 50370) Thengetpychar = "M"ElseIf(tmp>= 50371 And tmp<= 50613) Thengetpychar = "N"ElseIf(tmp>= 50614 And tmp<= 50621) Thengetpychar = "O"ElseIf(tmp>= 50622 And tmp<= 50905) Thengetpychar = "P"ElseIf(tmp>= 50906 And tmp<= 51386) Thengetpychar = "Q"ElseIf(tmp>= 51387 And tmp<= 51445) Thengetpychar = "R"ElseIf(tmp>= 51446 And tmp<= 52217) Thengetpychar = "S"ElseIf(tmp>= 52218 And tmp<= 52697) Thengetpychar = "T"ElseIf(tmp>= 52698 And tmp<= 52979) Thengetpychar = "W"ElseIf(tmp>= 52980 And tmp<= 53640) Thengetpychar = "X"ElseIf(tmp>= 53689 And tmp<= 54480) Thengetpychar = "Y"ElseIf(tmp>= 54481 And tmp<= 62289) Thengetpychar = "Z"Else '如果不是中⽂,则不处理getpychar = charEnd IfEnd FunctionFunction getpy(Str)For i = 1 To Len(Str)getpy = getpy&getpychar(Mid(Str, i, 1))NextEnd Function %>。

asp常用函数

asp常用函数

所有的关键字和运算等一切有关的关键词的集合HTML文件标记<html><head><!--><title><body>文字排版标记<br/><nobr><p><pre> 原始文字样式<center><blockquote> 向内缩排<h> 标题<strong>,<b> 粗体<em>,<i>,<cite> 斜体<U> 底线<strike> 删除线<blink> 文字闪烁<big> 大型字体<small> 小型字体<sup> 文字上标<SUB> 文字下标<basefont> 默认字体设置<font> 更改字体设置菜单标记<menu> 选项菜单<dir> 目录菜单<lh> 菜单格式(一)<ul> 菜单格式(二)<dl>,<dt>,<dd> 说明式菜单<ol>,<li> 标题菜单直线与表格标记<hr><table><tr><td><th><caption> 表格标题超链接标记<a> 锚图形标记<IMG> 插入图形框架标记<FRAME> 定义框架内容<NOFRAME> 不支持框架声明表单标记<FORM><INPUT><TEXTAREA><SELECT><OPTION>SCRIPT<script>VBSCRIPT标记索引基本运算+ 数字加法及字符串连接- 数字减法* 数字乘法/ 数字除法Mod 求余数\ 求商数& 字符串连接^ 次方= 相等<> 不相等>= 大于或等于> 大于<= 小于或等于< 小于Not 非And 且Or 或Xor 异或循环及决策if ....then 若...则...if ...then...else若...则...非else if...非若select case...群组选择条件end selectfor ... next计数循环while...wend 条件循环(一) do while...loop条件循环(二) do...loop while 条件循环(三) do until...loop条件循环(四) do...loop until 条件循环(五)数学函数Abs 绝对值Sgn 正负号Hex 转换成十六进制Oct 转换成八进制Sqr 平方根Int 取整数Fix 取整数Round 取整数Log 以e为底的对数Sin 正弦函数Cos 余弦函数Tan 正切函数字符串处理函数Len 字符串长度Mid 取部分字符串Left 从字符串开头取部分字符串Right 从字符串结尾取部分字符串Lcase 转换成小写Ucase 转换成大写Trim 清除字符串开头及结尾的空格符Ltrim 清除字符串开头空格符Rtrim 清除字符串结尾空格符Replace 替换字符串部分字符Instr 判断是否包含于另一个字符串(从起始搜寻) InstrRev 判断是否包含于另一个字符串(从结尾搜寻) Space 任意字符数的空格符String 任意字符数的任一字符StrReverse 反转字符串Split 以某字符分割字符串数据类型转换函数Cint 转换成整形Cstr 转换成字符串Clng 转换成常整数Cbool 转换成布尔函数Cdate 转换成日期函数CSng 转换成单精度CDbl 转换成双精度[page_break]日期时间函数Date 现在日期Time 现在时间NOw 现在日期时间DateAdd 增加日期DateDiff 两日期差DateSerial 日期设定Datevalue 日期设定Year 现在年份Month 现在月份Day 现在天Hour 现在时刻Minute 现在分钟Second 现在秒钟Timer 午夜距现在秒数TimeSerial 时间设定Timevalue 时间所属部分WeekDay 星期名称MonthName 月份名称其它函数Array 产生数组Asc 字符ASCII码Chr ASCII码字符Filter 过滤数组InputBox 输入窗口Join 合并数组中的元素MsgBox 信息窗口Lbound 数组下界Ubound 数组上界指令Const 设定常数Dim 定义变量或者数组Erase 清除数组ReDim 重新声明数组Randomize 起始随机数Rnd 取得随机数ASP对象Session对象IsEmpty 测试Session变量是否存在TimeOut 设定Session变量生存周期Abandon 强制清除Session变量Application对象IsEmpty 测试Application变量是否存在Lock 锁定Application变量Unlock 解除Lock指令的锁定Cookies对象Expires 设定Cookies变量的生存周期Connection对象Open 打开与数据库的连接Execute 打开Recordset对象Close 关闭Connection对象Recordset对象movefirst 将记录指针移至第一条movelast 将记录指针移至最后一条movenext 将记录指针移至下一条moveprevious 将记录指针移至上一条bof 测试是否为recordset的起始eof 测试是否为recordset的结束open 打开Recoreset对象close 关闭recordset对象fields 读取数据的子对象fileds.count 字段个数pagesize 每页记录条数absolutepage 设定为某页pagecount 总页数Absoluteposition 直接跳至某条记录sql="select * from bbs1 where xh like '%" & suibian & "%' or xq like '%" & suibian & "%'or bj like '%" & suibian & "%' or kc like '%" & suibian & "%'"。

ASP 常用的内置函数

ASP  常用的内置函数

ASP 常用的内置函数
介绍一个VBScript中为用户提供的各种类型内置函数。

使用他们可以使编写程序更加简单、快速、高效。

这些内置函数由VBScript预定义,其功能已经由VBSc ript系统实现,因此在编写程序时只需要直接调用即可。

1.字符串函数
在VBScript中字符串函数用于对字符串数据进行操作。

下面列出了一些常用的字符串函数及其功能,如表3-4所示。

2.数值函数
数值函数在程序中用于进行数值运算,如求某数的平方根,对数等。

表3-5列出了一些常用的数值函数。

表3-5 数值函数
3.转换函数
转换函数用于在Variant的各子类型之间进行数据类型的转换,这样方便进行各种运算。

下面将对常用的各种转换函数进行介绍,如表3-6所示。

表3-6 转换函数
4.布尔函数
VBScript中的布尔函数主要用于对数据类型的判断,以方便对该数据进行相应的处理。

例如,判断某数是否为数字类型。

在表3-7中列出了VBScript中常用的几个布尔函数。

表3-7 布尔函数
5.时间和日期函数
VBScript中的日期和时间函数用于获取系统的当前日期和时间,以及对日期时间类型数据进行处理。

表3-8列出了几种常用的时间和日期函数。

表3-8 时间和日期函数。

asp中常用的字符串安全处理函数集合(过滤特殊字符等)

asp中常用的字符串安全处理函数集合(过滤特殊字符等)

asp中常⽤的字符串安全处理函数集合(过滤特殊字符等)我们在注册的时候经常需要判断客户输⼊的内容是否合法,或者在页⾯传递参数的时候要判断,是否有客户恶意添加参数进⾏SQL注⼊等,这就需要1个函数去判断检测。

' ============================================' 判断是否安全字符串,在注册登录等特殊字段中使⽤' ============================================Function IsSafeStr(str)Dim s_BadStr, n, is_BadStr = "' &<>?%,;:()`~!@#$^*{}[]|+-=" & Chr(34) & Chr(9) & Chr(32)n = Len(s_BadStr)IsSafeStr = TrueFor i = 1 To nIf Instr(str, Mid(s_BadStr, i, 1)) > 0 ThenIsSafeStr = FalseExit FunctionEnd IfNextEnd Function⼤家可以⾃⾏添加BadStr字符串⾥⾯的字符,增加你想要过滤的字符即可。

下⾯是其他⽹友的补充'====================================='转换内容,防⽌意外'=====================================Function Content_Encode(ByVal t0)IF IsNull(t0) Or Len(t0)=0 ThenContent_Encode=""ElseContent_Encode=Replace(t0,"<","&lt;")Content_Encode=Replace(Content_Encode,">","&gt;")End IFEnd Function'====================================='反转换内容'=====================================Function Content_Decode(ByVal t0)IF IsNull(t0) Or Len(t0)=0 ThenContent_Decode=""ElseContent_Decode=Replace(t0,"&lt;","<")Content_Decode=Replace(Content_Decode,"&gt;",">")End IFEnd Function'====================================='过滤字符'=====================================Function FilterText(ByVal t0,ByVal t1)IF Len(t0)=0 Or IsNull(t0) Or IsArray(t0) Then FilterText="":Exit Functiont0=Trim(t0)Select Case t1Case "1"t0=Replace(t0,Chr(32),"&nbsp;")t0=Replace(t0,Chr(13),"")t0=Replace(t0,Chr(10)&Chr(10),"<br>")t0=Replace(t0,Chr(10),"<br>")Case "2"t0=Replace(t0,Chr(8),"")'回格t0=Replace(t0,Chr(9),"")'tab(⽔平制表符)t0=Replace(t0,Chr(10),"")'换⾏t0=Replace(t0,Chr(11),"")'tab(垂直制表符)t0=Replace(t0,Chr(12),"")'换页t0=Replace(t0,Chr(13),"")'回车 chr(13)&chr(10) 回车和换⾏的组合t0=Replace(t0,Chr(22),"")t0=Replace(t0,Chr(32),"")'空格 SPACEt0=Replace(t0,Chr(33),"")'!t0=Replace(t0,Chr(34),"")'"t0=Replace(t0,Chr(35),"")'#t0=Replace(t0,Chr(36),"")'$t0=Replace(t0,Chr(37),"")'%t0=Replace(t0,Chr(38),"")'&t0=Replace(t0,Chr(39),"")''t0=Replace(t0,Chr(40),"")'(t0=Replace(t0,Chr(41),"")')t0=Replace(t0,Chr(42),"")'*t0=Replace(t0,Chr(43),"")'+t0=Replace(t0,Chr(44),"")',t0=Replace(t0,Chr(45),"")'-t0=Replace(t0,Chr(46),"")'.t0=Replace(t0,Chr(47),"")'/t0=Replace(t0,Chr(58),"")':t0=Replace(t0,Chr(59),"")';t0=Replace(t0,Chr(60),"")'<t0=Replace(t0,Chr(61),"")'=t0=Replace(t0,Chr(62),"")'>t0=Replace(t0,Chr(63),"")'?t0=Replace(t0,Chr(64),"")'@t0=Replace(t0,Chr(91),"")'\t0=Replace(t0,Chr(92),"")'\t0=Replace(t0,Chr(93),"")']t0=Replace(t0,Chr(94),"")'^t0=Replace(t0,Chr(95),"")'_t0=Replace(t0,Chr(96),"")'`t0=Replace(t0,Chr(123),"")'{t0=Replace(t0,Chr(124),"")'|t0=Replace(t0,Chr(125),"")'}t0=Replace(t0,Chr(126),"")'~Case Elset0=Replace(t0, "&", "&amp;")t0=Replace(t0, "'", "&#39;")t0=Replace(t0, """", "&#34;")t0=Replace(t0, "<", "&lt;")t0=Replace(t0, ">", "&gt;")End SelectIF Instr(Lcase(t0),"expression")>0 Thent0=Replace(t0,"expression","e&#173;xpression", 1, -1, 0)End IfFilterText=t0End Function'====================================='过滤常见字符及Html'=====================================Function FilterHtml(ByVal t0)IF Len(t0)=0 Or IsNull(t0) Or IsArray(t0) Then FilterHtml="":Exit FunctionIF Len(Sdcms_Badhtml)>0 Then t0=ReplaceText(t0,"<(\/|)("&Sdcms_Badhtml&")", "&lt;$1$2")IF Len(Sdcms_BadEvent)>0 Then t0=ReplaceText(t0,"<(.[^>]*)("&Sdcms_BadEvent&")", "&lt;$1$2")t0=FilterText(t0,0)FilterHtml=t0End FunctionFunction GotTopic(ByVal t0,ByVal t1)IF Len(t0)=0 Or IsNull(t0) ThenGotTopic=""Exit FunctionEnd IFDim l,t,c, it0=Replace(Replace(Replace(Replace(t0,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")l=Len(t0)t=0For I=1 To lc=Abs(Asc(Mid(t0,i,1)))IF c>255 Then t=t+2 Else t=t+1IF t>=t1 ThengotTopic=Left(t0,I)&"…"Exit ForElseGotTopic=t0End IFNextGotTopic=Replace(Replace(Replace(Replace(GotTopic," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;") End FunctionFunction UrlDecode(ByVal t0)Dim t1,t2,t3,i,t4,t5,t6t1=""t2=Falset3=""For I=1 To Len(t0)t4=Mid(t0,I,1)IF t4="+" Thent1=t1&" "ElseIF t4="%" Thent5=Mid(t0,i+1,2)t6=Cint("&H" & t5)IF t2 Thent2=Falset1=t1&Chr(Cint("&H"&t3&t5))ElseIF Abs(t6)<=127 thent1=t1&Chr(t6)Elset2=Truet3=t5End IFEnd IFI=I+2Elset1=t1&t4End IFNextUrlDecode=t1End FunctionFunction CutStr(byVal t0,byVal t1)Dim l,t,c,iIF IsNull(t0) Then CutStr="":Exit Functionl=Len(t0)t1=Int(t1)t=0For I=1 To lc=Asc(Mid(t0,I,1))IF c<0 Or c>255 Then t=t+2 Else t=t+1IF t>=t1 ThenCutStr=Left(t0,I)&"..."Exit ForElseCutStr=t0End IFNextEnd FunctionFunction CloseHtml(ByVal t0)Dim t1,I,t2,t3,Regs,Matches,J,MatchSet Regs=New RegExpRegs.IgnoreCase=TrueRegs.Global=Truet1=Array("p","div","span","table","ul","font","b","u","i","h1","h2","h3","h4","h5","h6")For I=0 To UBound(t1)t2=0t3=0Regs.Pattern="\<"&t1(I)&"( [^\<\>]+|)\>"Set Matches=Regs.Execute(t0)For Each Match In Matchest2=t2+1NextRegs.Pattern="\</"&t1(I)&"\>"Set Matches=Regs.Execute(t0)For Each Match In Matchest3=t3+1NextFor j=1 To t2-t3t0=t0+"</"&t1(I)&">"NextNextCloseHtml=t0End Function以上就是asp中常⽤的字符串安全处理函数集合(过滤特殊字符等)的详细内容,更多关于字符串安全处理的资料请关注其它相关⽂章!。

再分享一些常用的ASP函数

再分享一些常用的ASP函数

'过滤sql注射字符function chksql(txt)if instr(txt,"'")>0 then txt=replace(txt,"'","")if instr(txt,";")>0 then txt=replace(txt,";","")if instr(txt,"""")>0 then txt=replace(txt,"""","")if instr(txt,"<")>0 then txt=replace(txt,"<","")if instr(txt,">")>0 then txt=replace(txt,">","")chksql=trim(txt)end function'HTTP采集:'GB2312编码的网站Function httpGet(url, method, data)url=cstr(url)dim Httpset Http=server.createobject("MSXML2.ServerXMLHTTP")Call Http.setTimeouts(900000,900000,900000,900000)if data<>"" thenHttp.open "GET",url + "?" + data,falseelseHttp.open "GET",url,falseend ifHttp.send()if Http.readystate<>4 thenexit functionend ifhttpGet=bytesToBSTR(Http.responseBody,"gb2312")set http=nothingif err.number<>0 then err.ClearEnd Function'UTF-8编码的网站,貌似GB2312的用这个要乱码Function httpGet2(url, method, data, charset)Dim xmlhttpSet xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")xmlhttp.SetTimeOuts 10000,20000,20000,100000if data<>"" thenxmlhttp.open method, url + "?" + data, Falseelsexmlhttp.open method, url, Falseend ifxmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset="&charsetxmlhttp.setRequestHeader "Content-Length", Len(data)xmlhttp.send (Null)If (xmlhttp.Status = 200) ThenhttpGet2 = xmlhttp.responseTextelseexit functionend ifSet xmlhttp = NothingEnd Function'编码转换Function BytesToBstr(body,Cset)dim objstreamset objstream = Server.CreateObject("adodb.stream") objstream.Type = 1objstream.Mode =3objstream.Openobjstream.Write bodyobjstream.Position = 0objstream.Type = 2objstream.Charset = CsetBytesToBstr = objstream.ReadTextobjstream.Closeset objstream = nothingEnd Function'编码转换Function encodeUrl(paraString,Encoding1,Encoding2) Session.CodePage=Encoding2encodeUrl=server.urlencode(paraString)Session.CodePage=Encoding1End Function'使用方法'encodeUrl(name,65001,936)'正在为替换超级链接Set reg=New RegExpreg.IgnoreCase = Truereg.Global = Truereg.MultiLine = Truereg.Pattern = "<a.+?href=(['""]?)([^>\s]+)\1.*?>([\S\s]+?)<\/a>" Set MC = reg.Execute(xmldata)For Each m In MCckURL = m.SubMatches(1)if instr(ckURL,"http://")>0 then response.Write ckURL & "<br>"Next'获取当前网址,含参数获取Function GetThisUrl()Dim ScriptAddress, M_ItemUrl, M_itemScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得当前地址M_ItemUrl = ""If (Request.QueryString <> "") ThenScriptAddress = ScriptAddress & "?"For Each M_item In Request.QueryStringIf InStr(page,M_Item)=0 ThenM_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"End IfNextend ifGetThisUrl = ScriptAddress & M_ItemUrlEnd Function'获取当前网址,完整的网址格式,包含参数部分的获取'可以获取到诸如/class/13.html?action=getdata&id=1Function GetUrl()Dim strHostName,strScriptName,strSubUrl,strRequestItemstrHostName=CStr(Request.ServerVariables("LOCAL_ADDR"))strScriptName=CStr(Request.ServerVariables("SCRIPT_NAME"))strSubUrl=""If Request.QueryString<>"" ThenstrScriptName=strScriptName&"?"For Each strRequestItem In Request.QueryStringIf InStr(strScriptName,strRequestItem)=0 ThenIf strSubUrl="" ThenstrSubUrl=strSubUrl&strRequestItem&"="&Server.URLEncode(Request.QueryString(""&strReq uestItem&""))ElsestrSubUrl=strSubUrl&"&"&strRequestItem&"="&Server.URLEncode(Request.QueryString(""&s trRequestItem&""))End IfEnd IfNextEnd IfGetUrl="http://"&strHostName&strScriptName&strSubUrlEnd Function'简单的,获取不到参数GetUrl ="http://"&Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")'获取来路网址If Request.ServerVariables("HTTP_REFERER")<>"" Thenresponse.write Request.ServerVariables("HTTP_REFERER")Elseresponse.write ""End IfSQL防注射代码:'--------定义部份------------------Dim Fy_Post,Fy_Get,Fy_cook,Fy_In,Fy_Inf,Fy_Xh,Fy_db,Fy_dbstr,logtxtaddOn Error Resume NextFy_In = "'|and|exec|insert|select|delete|update|count|chr|mid|master|truncate|char|declare|--|script" '常见的:Fy_In = "and|exec|insert|select|delete|update|chr|master|truncate|char|declare"Fy_Inf = split(Fy_In,"|")'--------POST部份------------------If Request.Form<>"" ThenFor Each Fy_Post In Request.FormFor Fy_Xh=0 To Ubound(Fy_Inf)If Instr(LCase(Request.Form(Fy_Post)),Fy_Inf(Fy_Xh))<>0 Thencall Writesqlinlog(now()&" + "&Request.ServerVariables("REMOTE_ADDR")&" + "&Request.ServerVariables("URL")&" + post + "&Fy_post&" + "&replace(Request.Form(Fy_post),"'","*"))call Endthesqlin("对不起,您输入的数据中含有非法字符,请重新输入!<br /><br />本次操作记录如下:<br />操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br />发生时间:"&Now()&"<br />操作页面:"&Request.ServerVariables("URL")&"<br />提交方式:POST<br />提交参数:"&Fy_Form&"<br />提交数据:"&Request.Form(Fy_Post))End IfNextNextEnd If'--------GET部份-------------------If Request.QueryString<>"" ThenFor Each Fy_Get In Request.QueryStringFor Fy_Xh=0 To Ubound(Fy_Inf)If Instr(LCase(Request.QueryString(Fy_Get)),Fy_Inf(Fy_Xh))<>0 Thencall Writesqlinlog(now()&" + "&Request.ServerVariables("REMOTE_ADDR")&" + "&Request.ServerVariables("URL")&" + get + "&Fy_get&" + "&replace(Request.QueryString(Fy_get),"'","*"))call Endthesqlin("对不起,您输入的数据中含有非法字符,请重新输入!<br /><br />本次操作记录如下:<br />操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br />发生时间:"&Now()&"<br />操作页面:"&Request.ServerVariables("URL")&"<br />提交方式:GET<br />提交参数:"&Fy_Get&"<br />提交数据:"&Request.QueryString(Fy_Get))End IfNextNextEnd If'--------cookies部份-------------------If Request.Cookies<>"" ThenFor Each Fy_cook In Request.CookiesFor Fy_Xh=0 To Ubound(Fy_Inf)If Instr(LCase(Request.Cookies(Fy_cook)),Fy_Inf(Fy_Xh))<>0 Thencall Writesqlinlog(now()&" + "&Request.ServerVariables("REMOTE_ADDR")&" + "&Request.ServerVariables("URL")&" + cookies + "&Fy_cook&" + "&replace(Request.Cookies(Fy_cook),"'","*"))call Endthesqlin("对不起,您输入的数据中含有非法字符,请重新输入!<br /><br />本次操作记录如下:<br />操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br />发生时间:"&Now()&"<br />操作页面:"&Request.ServerVariables("URL")&"<br />提交方式:POST<br />提交参数:"&Fy_cook&"<br />提交数据:"&Request.Cookies(Fy_cook))End IfNextNextEnd If'写入FSO记录Sub Writesqlinlog(txt)set fs_sqlin=server.CreateObject("Scripting.FileSystemObject")set file_sqlin=fs_sqlin.OpenTextFile(server.MapPath("SqlErrorLogs.txt"),8,True)file_sqlin.writeline txtfile_sqlin.closeset file_sqlin=nothingset fs_sqlin=nothingEnd Sub'sql注射,停止Sub Endthesqlin(txt)Response.Write txtResponse.Endend Sub万网域名查询接口:9.1域名check接口采用HTTP,POST,GET协议:调用URL:/cgi-bin/check.cgi参数名称:area_domain 值为标准域名,例:调用举例:/cgi-bin/check.cgi?area_domain= 返回XML:<?xml version="1.0" encoding="gb2312"?><property><returncode>200</returncode><key></key><original>210 : Domain name is available</original></property>返回XML结果说明:returncode=200 表示接口返回成功key=***.com表示当前check的域名original=210 : Domain name is available 表示域名可以注册original=211 : Domain name is not available 表示域名已经注册original=212 : Domain name is invalid 表示域名参数传输错误域名详情的查询接口:/cgi/whois?whois_nic=&type=domain。

ASP常用函数表

ASP常用函数表
FileLen(pathname) 传回档案的长度,单位是Byte。
Filter(sourcearray, match[, include[, compare]]) 搜寻字符串数组中的指定字符串,凡是数组元素中含有指定字符串,会将它们结合成新的字符串数组并传回。若是要传回不含指定字符串的数组元素,则include 参数设为False。compare 参数则是设定搜寻时是否区分大小写,此时只要给TextCompare 常数或1 即可。
Oct(number) 将数值参数转换为8 进制值。
Replace(expression, find, replace) 将字符串中find 参数指定的字符串转换为replace 参数指定的字符串。
Right(string,length) 由字符串右边开始取得length 参数设定长度的字符。
Str(number) 将数字转为字符串后传回。
StrReverse(expression) 取得字符串内容反转后的结果。
Tan(number) 取得某个角度的正切值。
TimeOfDay() 取得目前不包含日期的时间。
Timer() 取得由0:00 到目前时间的秒数,型态为Double。
Sin(number) 取得一个角度的正弦值。
Space(number) 取得number 参数设定的空白字符串。
Split(expression[, delimiter]) 以delimiter 参数设定的条件字符串来将字符串分割为字符串数组。
Sqrt(number) 取得一数值得平方根。
Weekday(date) 取的参数中的日期是一个星期的第几天,星期天为1、星期一为2、星期二为3 依此类推。

ASP常用字符串函数

ASP常用字符串函数

VBscript包括大量用于操作字符串的函数。

当你需要操作来自HTML表单或数据库的数据时,你会发现这些函数非常有用。

你可以用这些函数来拼接字符串,抽取字符串,搜索字符串,和比较字符串。

拼接字符串当你需要用短的字符串构造长字符串时,要用到拼接运算符(&)。

下面的例子用短的表达式构造了一个句子:<%exp1=”The house ”exp2=”is on a ”exp3=”hill.”sentence=exp1&exp2&exp3%>你也可以用加号(+)来拼接字符串。

但是,这种方法不值得推荐。

与&运算符不同,+运算符并不保证返回一个字符串。

考虑如下的例子:<%myvar=1%><%=”The value of myvar is:”&myvar%><%=”The value of myvar ia:”+myvar%>当用拼接运算符&来输出myvar的值时,语句执行正常。

运算符&自动把变量myvar 的值转换为字符串。

但是,当使用运算符+时,将出现错误,因为这个语句实际上会试图将myvar的值加到字符串表达式上。

如果你有一个字符数组,你可以用函数JOIN()连接数组中所有的字符串。

这里有一个例子:<%dim myarray(2)myarray(0)=”The house ”myarray(1)=”is on a ”myarray(2)=”hill.”sentence=JOIN(myarray)%>当这段脚本执行后,变量sentence的值等于数组myarray中所有的字符串连接在一起。

要使用这个函数,myarray必须是一个一维数组(一个列表)。

你可以给该函数提供一个可选的第二参数,作为与空格不同的分隔符:senten ce=JOIN(myarray,”/”)在这个例子中,函数JOIN()的返回值是The house/is on a/hill.如果你需要加入一些空格,你可以使用函数SPACE(),象这样:sentence=”Over”&SPACE(20)&”There.”在这个例子中,变量sentence的值等于被20个空格隔开的Over和There。

ASP常用的库函数大全

ASP常用的库函数大全

<%'判断文件名是否合法Function isFilename(aFilename)Dim sErrorStr,iNameLength,iisFilename=TRUEsErrorStr=Array("/","\",":","*","?","""","<",">","|") iNameLength=Len(aFilename)If iNameLength<1 Or iNameLength=null Then isFilename=FALSEElseFor i=0 To 8If instr(aFilename,sErrorStr(i)) ThenisFilename=FALSEEnd IfNextEnd IfEnd Function'去掉字符串头尾的连续的回车和空格function trimVBcrlf(str)trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))end function'去掉字符串开头的连续的回车和空格function ltrimVBcrlf(str)dim pos,isBlankCharpos=1isBlankChar=truewhile isBlankCharif mid(str,pos,1)=" " thenpos=pos+1elseif mid(str,pos,2)=VBcrlf thenpos=pos+2elseisBlankChar=falseend ifwendltrimVBcrlf=right(str,len(str)-pos+1)end function'去掉字符串末尾的连续的回车和空格function rtrimVBcrlf(str)dim pos,isBlankCharpos=len(str)isBlankChar=truewhile isBlankChar and pos>=2if mid(str,pos,1)=" " thenpos=pos-1elseif mid(str,pos-1,2)=VBcrlf thenpos=pos-2elseisBlankChar=falseend ifwendrtrimVBcrlf=rtrim(left(str,pos))end function'判断Email是否有效,返回1表示正确Function isEmail(aEmail)Dim iLocat,v,iLength,i,checkletterIf instr(aEmail,"@") = 0 Or instr(aEmail,".") = 0 ThenisEmail=0EXIT FUNCTIONEnd IfiLocat=instr(aEmail,"@")If instr(iLocat,aEmail,".")=0 Or instr(iLocat+1,aEmail,"@")>0 ThenisEmail=0EXIT FUNCTIONEnd IfIf left(aEmail,1)="." Or right(aEmail,1)="." Or left(aEmail,1)="@" Or right(aEmail,1)="@" Then isEmail=0EXIT FUNCTIONEnd Ifv="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@" iLength=len(aEmail)For i=1 To iLengthcheckletter=mid(aEmail,i,1)If instr(v,checkletter)=0 ThenisEmail=0EXIT FUNCTIONEnd IfNextisEmail=1End Function'测试用:显示服务器信息Sub showServerDim nameResponse.write "<Table border=1 bordercolor=lightblue CELLSPACING=0>"for each name in request.servervariablesResponse.write "<tr>"Response.write "<td>"&name&"</td>"Response.write "<td>"&request.servervariables(name)&"<br></td>"Response.write "</tr>"nextResponse.write "</table>"End Sub'测试用:显示Rs结果集以及字段名称Sub showRs(rs)Dim strTable,whateverResponse.write "<center><table><tr>"for each whatever in rs.fieldsresponse.write "<td><b>" & & "</B></TD>"nextstrTable = "</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) thentxt2Html=""exit Functionend ifstr=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=strEnd Function'测试用:显示调试错误信息Sub showErrorDim sErrMsgsErrMsg=Err.Source&" "&Err.DescriptionResponse.write "<center>"&sErrMsg&"</center>"Err.clearEnd Sub'显示文字计数器Sub showCounterDim fs,outfile,filename,countfilename=server.mappath("count.txt")Set fs = CreateObject("Scripting.FileSystemObject")If fs.fileExists(filename) ThenSet outfile=fs.openTextFile(filename,1)count=outfile.readlinecount=count+1Response.write "<center>浏览人次:"&count&"<center>" outfile.closeSet outfile=fs.CreateTextFile(filename)outfile.writeline(count)ElseSet outfile=fs.openTextFile(filename,8,TRUE)count=0outfile.writeline(count)END IFoutfile.closeset fs=nothingEnd Sub%>Array()FUNCTION: 返回一个数组SYNTAX: Array(list)ARGUMENTS: 字符,数字均可EXAMPLE: <%Dim myArray()For i = 1 to 7Redim 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组件的实例。

asp常用函数集(ASPcommonfunctionsets)

asp常用函数集(ASPcommonfunctionsets)

asp 常用函数集(ASP common function sets)1.function array ()Function: create an array variableFormat: array (list)Argument: list is the column of each column in the array variable, with a comma interval in the middleExample:I = array (〃1〃,〃2〃,〃3〃)% >Results: I is assigned as an array2.function Cint ()Function: converts an expression / other type of variable into an integer type (int)Format: Cint (expression)Argument: expression is any valid expression / other type of variableExample:<F = 234Response, write cINT (f) + 2 % >Results: 236The function Cint () converts character 234 to integer 234. and returns 0 if the expression is null or invalid:3.function: Creatobject ()Function: creates and returns a ActiveX objectFormat: Creatobject (obname)The parameter bName is the name of the objectExample:<Set con = Server.CreateObject ("ADODB. Connection")% >Result:4.function Cstr ()a character type (string)Format: Cstr (expression)Argument: expression is any valid expression / other type of variable Example:<S = 3 + 2Response, write "The, result, is:" & cStr (s)% >Results: function Cstr () converts integer 5 to character "5”5.function Date ()Function: returns the date of the current system (server end) Format: Date ()Parameter: NoneExamples of date ()% >Results: 05/10/006.function Dateadd ()Function: calculates a specified time andFormat: DateAdd (timeinterval, number, date)Argument: timeinterval is the time unit (month, day, day). Number is the time interval value, and date is the time start pointExample:<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/993:34:45 PMamong〃M〃 = "month"”;"D" = "day"”;If it is in currentDate format, then,〃TT〃〃1〃〃H = hour ;S = second ;7.function Datediff ()Function: calculates a specified amount of time differenceFormat: DateDiff (timeinterval, datel, date2[, firstdayofweek[, firstdayofyear>)Argument: timeinterval is a time unit: datel and date2 are valid date expressions: firstdayofweek and firstdayofyear are optionalExample:FromDate = #8/4/99#ToDate = #1/1/2000#Response, write "There are" & _DateDiff (D, fromDate, toDate & _)"Days, to, millenium, from, 8/4/99..% >Results: There, are, , days, to, millenium, from, 8/4/99.8.function day ()Function: returns an integer value corresponding to a certain month of the day Format: Day (date)Argument: date is a valid date expression;For example < = date (#8/4/99#)% >Results: 49.function formatcurrency ()Function: convert to currency format Format: formatcurrency (expression [, digit [, leadingdigit [, parent, groupdigit>>)Argument: expression is a valid numeric expression: digit stands for the digitsafter the decimal point: leadingdigit, paren, and groupdigit are optionalFor example < = FormatCurrency (34. 3456)% >Result 34. 3510.function Formatdatetime ()Function: formatting date expressions / variablesFormat: formatdatetime (date[, nameformat])Argument: date is a valid date expression / variable: nameformat is the specified date format constant nameFor example < = formatdatetime (08/04/99, vblongdate)% >Results: Wednesday, August 04,One thousand nine hundred and ninety-nineExplain:describeReturns an expression that has been formatted as date or time.grammarFormatDateTime (Date[, NamedFormat])The syntax of the FormatDateTime function has the following parameters:Parameter descriptionDate optional. A date expression to be formatted.NamedFormat optional. Indicates the value of the date / time format used, and if omitted, use vbGeneralDate.Set upThe NamedFormat parameter can have the following values:Constant value descriptionVbGeneralDate 0 displays date and / or time. If there is a part of the date, the part is displayed as a short date format. If there is a part of the time, the part is shown as a long format. If all of them exist, all parts are displayed.VbLongDate 1 displays the date in the long date format specified in the computer locale.VbShortDate 2 displays the date in a short date format specified in the computer locale.VbLongTime 3 displays the time in the time format specified in the computer locale.VbShortTime 4 displays the time in 24 hour format (hh:mm).ExplainThe following example uses the FormatDateTime function to format anexpression into a long date type and assigns it to MyDateTime:Function GetCurrentDate"FormatDateTime formats the date type as long date type. GetCurrentDate = FormatDateTime (Date, 1)End Function11.function Isnumeric ()Function: returns a Boolean value, determines whether a variable is a numeric variable, or any other variable that canbe converted into numbersFormat: IsNumeric (expression)Argument: expression is an arbitrary variableExample:<I = 234”Response, write IsNumeric (I)% >Results: true.12.function Isobject ()Function: returns a Boolean value to determine whether a variable is an object variable,Format: isobject (expression)Argument: expression is an arbitrary variableExample:Set con = server.creatobject ("adodb. connection")Response, write isobject (CON)% >Results: true13.function: Lbound ()Function: returns the lower bound of an arrayFormat: Lbound (arrayname[, dimension])Argument: arrayname is an array variable, and dimension is any entry Example:<I = array (〃1〃,〃2〃,〃3〃)Response, write lbound (I)% >Results: 014.function Lease ()Function: transforms all characters of a character type variable into lower case charactersFormat: Lease (string)Argument: string is a string variableExample:<STR = "THIS, is, Lease”!”Response, write Lease (STR)% >Results: this, is, lease!15.function left ()Function: to intercept the front part of a string;Format: left (string, length)Argument: string string, the length of length interception Example: < = left ("this is a test!”, 6)% >Results: this I16.function len ()Function: returns the length of a string or the length of a variableFormat: len (string, *varname)Argument: string string: Varname any variable name Example:<Strtest = "this, is, a, test”!”Response, write left (strtest)% >Results: 1517.function Itrim ()Function: removes the space before the string Format: Itrim (string)Argument: string stringExample: < = Itrim ("this is a test!”)Results: this, is, a, test!18.function Mid ()Function: intercepts strings from stringsFormat: Mid (string, start, [length]])Parameter: string string, the starting point of start interception, and the length of length to interceptExample:<Strtest = "this, is, a, test”,今天是星期一。

asp常用自定义函数大全(网站开发必备)

asp常用自定义函数大全(网站开发必备)

函数列表:'1:建立数据库的连接ConnOpen(DataBaseConnectStr,DBType,Conn_object)'2:断开数据库的连接ConnClose(Conn_object)'3:防止SQL注入SafeRequest(paraName,paraType)'4:格式化日期DateFormat(dateStr,dateType)'5:显示错误提示ShowErr(errStr)'6:查询字符串中特定数据SelectStr(contentStr,patternStr,patternNum)'7:过滤指定字符Leach(contentStr,badWords)'8:远程文件内容抓取Seize(urlStr)'9:数据流编码处理BytesToBstr(body,cset)'10:编码cookies codeCookie(contentStr)'11:解码cookies DecodeCookie(contentStr)'12:检验数据提交来源是否合法ChkPost()'13:个性化加密MyEncrypt(StrPassword)'14:禁止浏览器缓存本页NoBuffer()'15:网页格式化输入文本HTMLEncode(fString)'16:从头部截取字符串的指定长度(按字符数算) GotTopic(Str,StrLen)'17:检测验证码CheckRadomPass(RadomPass)'18:生成验证码GetCode()'19:获取客户端操作系统版本GetSystem()'20:数据库事务处理ConnManage(Conn_object)'21:快速排序(递归)QuickSort(arr,Low,High)'22:将数组的元素以特定字符串连起来arr_join(arr,character)'23:返回字符串以某分割符分割的数目count_character(str,character)'24:截取含有分割符的字符串中指定数目的字符串inter_str_by_character_num(str,character,start,num)'25:利用Stream下载文件downloadFile(strFile)'26:返回信息send_back(ResultWords)'27:获取错误信息get_err()'28:与SafeRequest相反SafeResponse(content)'29:保存远程图片SaveRemoteFile(LocalFileName,RemoteFileUrl)'30: ...dim language_arr(10)language_arr(0) = "数据库连接的参数设置错误!"language_arr(1) = "数据库连接的类型参数设置错误!"language_arr(2) = "数据库连接失败!"language_arr(3) = "非法的参数值!"language_arr(4) = "参数值不是有效的日期格式!"language_arr(5) = "操作失败!"language_arr(6) = "栏目有重名!"language_arr(7) = "栏目名称为空!"language_arr(8) = "栏目文件夹创建失败!"language_arr(9) = "您没有此权限!"'============================================================================================================================'函数ID:1'函数作用:建立数据库的连接'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-15 10:28'修改时间:'传人参数:' connectStr:数据库连接字符串' connectType:数据库类别-数字型,0为Access,1为MS SQL'返回值:'=================================================================== =========================================================sub ConnOpen(DataBaseConnectStr,DBType,Conn_object)Set Conn_object = Server.Createobject("adodb.connection")if DataBaseConnectStr = "" then call ShowErr(language_arr(0))if DBType = 0 thenConn_object.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DataBaseConnectStrelseif DBType = 1 thenConn_object.Open "Provider=SQLOLEDB.1;" & DataBaseConnectStrelsecall ShowErr(language_arr(1))end iferr.clearend sub'=================================================================== ========================================================='函数ID:2'函数作用:断开数据库的连接'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 15:10'修改时间:'传人参数:'返回值:'=================================================================== =========================================================Sub ConnClose(Conn_object)Conn_object.closeset Conn_object = nothingEnd sub'=================================================================== ========================================================='函数ID:3'函数作用:防止SQL注入'作者名称:/infoview/Article_2906.html'建立时间:2006-2-16 15:32'修改时间:'传人参数:' paraName:参数名称-字符型' paraType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)'返回值:' 过滤后的字符串'=================================================================== =========================================================Function SafeRequest(paraName,paraType)dim paraValueparaValue = Request(paraName)select case paraTypecase 0paraValue = replace(paraValue,"'","[system:34]")paraValue = replace(paraValue,"=","[system:61]")case 1if not IsNumeric(paraValue) then call ShowErr(language_arr(3))case -1if not IsNumeric(paraValue) then call ShowErr(language_arr(3))if paraValue = "" then paraValue = 0case elseif len(paraValue) > paraType then call ShowErr(language_arr(3))paraValue = replace(paraValue,"'","[system:34]")paraValue = replace(paraValue,"=","[system:61]")end selectSafeRequest = paraValueEnd function'=================================================================== ========================================================='函数ID:4'函数作用:格式化日期'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 15:45'修改时间:'传人参数:' dateStr:日期字符串' paraType:日期类型-数字型'返回值:' 格式化后的日期'=================================================================== =========================================================Function DateFormat(dateStr,dateType)Dim dateStringif IsDate(dateStr) = False thencall ShowErr(language_arr(4))end ifSelect Case dateTypeCase "1"dateString = Year(dateStr)&"-"&Month(dateStr)&"-"&Day(dateStr)Case "2"dateString = Year(dateStr)&"."&Month(dateStr)&"."&Day(dateStr)Case "3"dateString = Year(dateStr)&"/"&Month(dateStr)&"/"&Day(dateStr)Case "4"dateString = Month(dateStr)&"/"&Day(dateStr)&"/"&Year(dateStr)Case "5"dateString = Day(dateStr)&"/"&Month(dateStr)&"/"&Year(dateStr)Case "6"dateString = Month(dateStr)&"-"&Day(dateStr)&"-"&Year(dateStr)Case "7"dateString = Month(dateStr)&"."&Day(dateStr)&"."&Year(dateStr)Case "8"dateString = Month(dateStr)&"-"&Day(dateStr)Case "9"dateString = Month(dateStr)&"/"&Day(dateStr)Case "10"dateString = Month(dateStr)&"."&Day(dateStr)Case "11"dateString = Month(dateStr)&language_arr(6)&Day(dateStr)&language_arr(7)Case "12"dateString = Day(dateStr)&language_arr(7)&Hour(dateStr)&language_arr(8)case "13"dateString = Day(dateStr)&language_arr(7)&Hour(dateStr)&language_arr(8)Case "14"dateString = Hour(dateStr)&language_arr(8)&Minute(dateStr)&language_arr(9)Case "15"dateString = Hour(dateStr)&":"&Minute(dateStr)Case "16"dateString = Year(dateStr)&language_arr(5)&Month(dateStr)&language_arr(6)&Day(dateStr)&languag e_arr(7)Case ElsedateString = dateStrEnd SelectDateFormat = dateStringEnd Function'=================================================================== ========================================================='函数ID:5'函数作用:显示错误提示'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 16:29'修改时间:'传人参数:' errStr:错误提示-字符型'返回值:返回提交页面'=================================================================== =========================================================sub ShowErr(errStr)Response.Write("<script>alert("""&errStr&""");location.href=""javascript:history.back()"";</ script>")Response.EndEnd sub'=================================================================== ========================================================='函数ID:6'函数作用:查询字符串中特定数据'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 16:40'修改时间:'传人参数:' contentStr:查询字符串' patternStr:匹配式字符串' patternNum:查询定位-数字型'返回值:' 找不到返回false' patternNum为-1返回所有匹配字符串并以[10]隔开' 否则返回指定位置的字符串'=================================================================== =========================================================Function SelectStr(contentStr,patternStr,patternNum)dim objRegExp,matches,matcheif contentStr = "" thencall ShowErr(language_arr(12))end ifSet objRegExp=new RegExp '建立正则表达式objRegExp.pattern = patternStr '设置模式objRegExp.IgnoreCase =False '设置是否区分字符大小写objRegExp.Global=true '设置全局可用性objRegExp.pattern = patternStr '匹配式if objRegExp.test(contentStr) = false then '全局匹配SelectStr = falseelseSet matches = objRegExp.Execute(contentStr) '执行搜索if patternNum = -1 thenfor each matche in matchesSelectStr = SelectStr &"[10]"& matche.valuenextelseSelectStr = matches.Item(patternNum).valueend ifend ifSet objRegExp=NothingEnd Function'=================================================================== ========================================================='函数ID:7'函数作用:过滤指定字符'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 16:59'修改时间:'传人参数:' contentStr:源字符串' badWords:要过滤的字符串,若数目大于1则用英文状态的"^"隔开'返回值:' 返回过滤后的字符串'=================================================================== =========================================================Function Leach(contentStr,badWords)dim badWordsArr,ibadWordsArr = Split(badWords,"^")for i = 0 to UBound(badWordsArr)contentStr = replace(contentStr,badWordsArr(i),"")nextleach = contentStrend Function'=================================================================== ========================================================='函数ID:8'函数作用:远程文件内容抓取'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 17:24'修改时间:'传人参数:' urlStr:远程文件地址'返回值:' 返回远程文件内容'=================================================================== =========================================================function Seize(urlStr)dim connectif urlStr = "" thencall ShowErr(language_arr(13))elseSet connect = CreateObject("Microsoft.XMLHTTP") '建立XMLHTTP对象connect.open "GET",urlStr,false '设置参数,通信方式为get,请求为同步,后面还有两个可选属性:userID,password用于用户验证connect.send() '数据发送,Send方法的参数类型可以是字符串、DOM树或任意数据流Seize = BytesToBStr(connect.responseBody,"GB2312") '返回信息,编码为中文set connect = nothingend ifend function'=================================================================== ========================================================='函数ID:9'函数作用:数据流编码处理'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 17:30'修改时间:'传人参数:' body:数据内容' cset:编码格式'返回值:' 编码处理后的信息'=================================================================== =========================================================Function BytesT oBstr(body,cset)dim objstreamset objstream = Server.CreateObject("adodb.stream")objstream.Type = 1 '以二进制模式打开objstream.Mode =3objstream.Openobjstream.Write bodyobjstream.Position = 0objstream.Type = 2objstream.Charset = csetBytesToBstr = objstream.ReadT extobjstream.Closeset objstream = nothingEnd Function'=================================================================== ========================================================='函数ID:10'函数作用:编码cookies'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-16 17:36'修改时间:'传人参数:' contentStr:数据内容'返回值:' 编码处理后的信息,字符以"a"隔开'=================================================================== =========================================================Function codeCookie(contentStr)Dim i,returnStrFor i = Len(contentStr) to 1 Step -1returnStr = returnStr & Ascw(Mid(contentStr,i,1))If (i <> 1) Then returnStr = returnStr & "a"NextCodeCookie = returnStrEnd Function'=================================================================== ========================================================='函数ID:11'函数作用:解码cookies'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-17 16:58'修改时间:'传人参数:' contentStr:数据内容'返回值:' 解码处理后的信息'=================================================================== =========================================================Function DecodeCookie(contentStr)Dim iDim StrArr,StrRtnStrArr = Split(contentStr,"a")For i = 0 to UBound(StrArr)If isNumeric(StrArr(i)) = True ThenStrRtn = Chrw(StrArr(i)) & StrRtnElseStrRtn = contentStrExit FunctionEnd IfNextDecodeCookie = StrRtnEnd Function'=================================================================== ========================================================='函数ID:12'函数作用:检验数据提交来源是否合法'作者名称:茫仔xiamangmang@ 博客:'建立时间:2006-2-18 18:55'修改时间:'传人参数:''返回值:' Boolean'=================================================================== =========================================================Function ChkPost()Dim server_v1,server_v2Chkpost=Falseserver_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))If Mid(server_v1,8,len(server_v2))=server_v2 Then Chkpost=TrueEnd Function'=================================================================== =========================================================。

ASP常用函数集范文

ASP常用函数集范文

功能:创建一个数组变量格式:array(list)参数:list为数组变量中的每个数值列,中间用逗号间隔例子:<%i=array(“1”,”2”,”3”)%>结果:i被赋予为数组2.函数Cint()功能:将一表达式/其它类型的变量转换成整数类型(int)格式:Cint(expression)参数:expression是任何有效的表达式/其它类型的变量例子:<%f=”234”response.write cINT(f)+2%>结果:236函数Cint()将字符”234”转换成整数234.如果表达式为空,或者无效时,返回值为0;3.函数:Creatobject()功能:创建及返回一个ActiveX对象.格式:Creatobject(obname)参数bname是对象的名称例子:<%Set con=Server.CreateObject(“ADODB.Connection”)%>结果:功能:将一表达式/其它类型的变量转换成字符类型(string)格式:Cstr(expression)参数:expression是任何有效的表达式/其它类型的变量例子:<%s=3+2response.write”The result is:”&cStr(s)%>结果:函数Cstr()将整数5转换成字符”5”.5.函数Date()功能:返回当前系统(server端)的日期格式:Date()参数:无例子<%date()%>结果:05/10/006.函数Dateadd()功能:计算某个指定的时间和格式:dateadd(timeinterval,number,date)参数:timeinterval是时间单位(月,日..);number是时间间隔值,date是时间始点.例子:<%currentDate=#8/4/99#newDate=DateAdd(“m”,3,currentDate)response.write newDate%><%currentDate=#12:34:45PM#newDate=DateAdd(“h”,3,currentDate)response.write newDate%>结果:11/4/993:34:45PM其中“m”=”month”;“d”=”day”;如果是currentDate格式,则,“h”=”hour”;“s”=”second”;7.函数Datediff()功能:计算某量个指定的时间差格式:datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]])参数:timeinterval是时间单位;date1,date2是有效的日期表达式,firstdayofweek,firstdayofyear是任意选项.例子:<%fromDate=#8/4/99#toDate=#1/1/2000#response.write”There are”&_DateDiff(“d”,fromDate,toDate)&_“days to millenium from8/4/99.”%>结果:There are150days to millenium from8/4/99.8.函数day()功能:返回一个整数值,对应于某月的某日格式:day(date)参数:date是一个有效的日期表达式;例子<%=date(#8/4/99#)%>结果:49.函数formatcurrency()功能:转换成货币格式格式:formatcurrency(expression[,digit[,leadingdigit[,paren[,groupdigit]]]])参数:expression是有效的数字表达式;digit表示小数点后的位数;leadingdigit,paren,groupdigit是任意选项.例子<%=FormatCurrency(34.3456)%>结果34.3510.函数Formatdatetime()功能:格式化日期表达式/变量格式:formatdatetime(date[,nameformat])参数:date为有效的日期表达式/变量;nameformat是指定的日期格式常量名称.例子<%=formatdatetime(“08/04/99”,vblongdate)%>结果:Wednesday,August04,1999说明:描述返回表达式,此表达式已被格式化为日期或时间。

好!asp常用函数大全

好!asp常用函数大全
Request.QueryString(Varible)[(Index).Count]
Request.form("PassStrName"):读取Post方法传递的纯表单域的值
Request.Form(Parameter)[(Index).Count]
Request.ServerVaribles(Server Environment Variable):读取客户端系统环境变量,详见参考
mid(str,起始字符,[读取长度]):截取字符串中间子字符串
left(str,nlen):从左边起截取nlen长度子字符串
right(str,nlen):从右边起截取nlen长度子字符串
Lcase(str):字符串转成小写
Ucase(str):字符串转成大写
trim(str):去除字符串两端空格
注:Session与Application变量都可以用来存储数组和系统对象,引用方法是变量名相当于数组名而已,但不能直接改变其值,需要借助临时
数组修改值后,再赋给Session与Application变量
Server:
Server.MapPath("FileUrl"):映射文件名的服务器站点绝对地址,Path=Server.MapPath(./)可以得到虚拟目录根路径
Response.write StrVar/"String":向网页写出参数值或字符串等同于在Html标记中嵌入
Response.End:停止页面编译,并将已经编译内容输出到浏览器
Response.Buffer=True|False:页面编译时是否使用缓存的设置,一般在页面头部设置
Response.Flush:强制输出页面已编译部分内容

一个实用的ASP字符串、数组输出函数

一个实用的ASP字符串、数组输出函数

一个实用的ASP字符串、数组输出函数asp对于一般的字符串输出,使用内置对象的Response.Write即可,但对于数组的输出就显得有些力不从心了,下面这个函数就可以解决这个问题,虽然很简单的函数,但对于调试或者数组输出需要的项目来使用是非常方便的。

程序代码<%PRintln("something")println(array("some", "more", "lines"))Response.write array("some", "more", "lines")function arrayize(value)if isArray(value) thenarrayize = valueelseif isEmpty(value) thenarrayize = array()elsearrayize = array(value)end ifend functionfunction [](value)[] = arrayize(value)end functionsub println(line)for each l in [](line)response.write(l)nextend sub%>补充一下,如果只是单纯的一维数组的话,可以用程序代码<%Response.Write(Join(arrT est, "<br />"))%>来实现同样的输出结果。

附上关于Join函数的简短解释:引用内容Join 函数返回一个字符串,此字符串由包含在数组中的许多子字符串联接创建。

Join(list[,delimiter])参数list必选项。

包含要联接的子字符串一维数组。

Delimiter可选项。

在返回字符串中用于分隔子字符串的字符。

写出以下ASP函数的功能

写出以下ASP函数的功能

写出以下ASP函数的功能Len:返回字符串内字符的数目,或是存储一变量所需的字节数Trim:是去掉字符串前后的空格Now:根据计算机系统设定的日期和时间返回当前的日期和时间值Replace:替换的作用拓展:asp Fix、Int、Round、CInt函数使用说明Fix(number) 和Int(number) 都是返回数字的整数部分。

number 为正数时,二者返回值一样。

比如:Fix(3.6)=3,Int(3.6)=3。

number 为负数时,Fix 直接去除小数部分,Int 返回小于或等于number 的第一个负整数。

比如:Fix(-3.6)=-3,Int(-3.6)=-4。

Round(number, numdecimalplaces),第二个参数表示从小数点右边第几位开始实行四舍五入,可以省略,默认是0,即四舍五入返回整数。

CInt(number) 利用四舍五入的方式删除小数部分。

如果Round 的第二个参数省略,那么Round 和CInt 功能是一样的。

number 为正数时,Round(3.6)=4,CInt(3.6)=4。

注意,当小数部分恰好是0.5时,总是将其四舍五入为最接近的偶数。

比如Round(3.5)=4,Round(4.5)=4。

number 为负数时,可以这样理解(假设n 为正数):Round(-n) = -Round(n),比如:Round(-3.5) = -4。

CInt(-n) = -CInt(n),比如:CInt(-99.8) = -100。

asp中的几个取整函数是:fix(),int(),round();Int(number)、Fix(number)函数返回数字的整数部分。

number 参数可以是任意有效的数值表达式。

如果number 参数包含Null,则返回Null。

例:复制代码代码如下:response.write int(2.14) 2response.write fix(2.14) 2response.write int(2.54) 2response.write int(2.54) 2Int 和Fix 函数都删除number 参数的小数部分并返回以整数表示的结果。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

asp字符串处理通用函数
Len 语法Len(string|varname) 功能返回字符串内字符的数目,或是存储一变量所需的字节数。

Trim语法Trim(string) 功能将字符串前后的空格去掉
Ltrim语法Ltrim(string) 功能将字符串前面的空格去掉
Rtrim语法Rtrim(string) 功能将字符串后面的空格去掉
Mid语法Mid(string,start,length) 功能从string字符串的start字符开始取得length长度的字符串,如果省略第三个参数表示从start字符开始到字符串结尾的字符串
Left语法Left(string,length) 功能从string字符串的左边取得length长度的字符串
Right语法Right(string,length) 功能从string字符串的右边取得length长度的字符串
LCase语法LCase(string) 功能将string字符串里的所有大写字母转化为小写字母
UCase语法UCase(string) 功能将string字符串里的所有大写字母转化为大写字母
StrComp语法StrComp(string1,string2[,compare]) 功能返回string1字符串与string2字符串的比较结果,如果两个字符串相同,则返回0,如果小于则返回-1,如果大于则返回1 InStr语法InStr(string1,string2[,compare]) 功能返回string1字符串在string2字符串中第一次出现的位置
Split语法Split(string1,delimiter[,count[,start]]) 功能将字符串根据delimiter拆分成一维数组,其中delimiter用于标识子字符串界限。

如果省略,使用空格("")作为分隔符。

count返回的子字符串数目,-1指示返回所有子字符串。

start为1执行文本比较;如果为0或者省略执行二进制比较。

Replace语法Replace(expression,find,replacewith[,compare[,count[,start]]]) 功能返回字符串,其中指定数目的某子字符串(find)被替换为另一个子字符串(replacewith)。

1、Len函数示例:
下面的示例利用Len 函数返回字符串中的字符数目:
Dim MyString
MyString = Len("VBSCRIPT") ''MyString 包含82、Trim、Ltrim、Rtrim函数示例:
2、LTrim, RTrim, 和Trim函数示例:
下面的示例利用LTrim, RTrim, 和Trim 函数分别用来除去字符串开始的空格、尾部空格、开始和尾部空格:
Dim MyVar
MyVar = LTrim(" vbscript ") ''MyVar 包含"vbscript "。

MyVar = RTrim(" vbscript ") ''MyVar 包含" vbscript"。

MyVar = Trim(" vbscript ") ''MyVar 包含"vbscript"。

3、Mid函数示例:
下面的示例利用Mid 函数返回字符串中从第四个字符开始的六个字符:
Dim MyVar
MyVar = Mid("VB脚本is fun!", 4, 6) ''MyVar 包含"Script"。

4、Left函数示例:
下面的示例利用Left 函数返回MyString 的左边三个字母:
Dim MyString, LeftString
MyString = "VBSCript"
LeftString = Left(MyString, 3) ''LeftString 包含"VBS
5、Right函数示例:
下面的示例利用Right 函数从字符串右边返回指定数目的字符:
Dim AnyString, MyStr
AnyString = "Hello World" ''定义字符串。

MyStr = Right(AnyString, 1) ''返回"d"。

MyStr = Right(AnyString, 6) '' 返回" World"。

MyStr = Right(AnyString, 20) '' 返回"Hello World"。

6、LCase函数示例:
下面的示例利用LCase 函数把大写字母转换为小写字母:
Dim MyString
Dim LCaseString
MyString = "VBSCript"
LCaseString = LCase(MyString) '' LCaseString 包含"vbscript"。

7、UCase函数示例:
下面的示例利用UCase 函数返回字符串的大写形式:
Dim MyWord
MyWord = UCase("Hello World") '' 返回"HELLO WORLD"。

8、StrComp函数示例:
下面的示例利用StrComp 函数返回字符串比较的结果。

如果第三个参数为1 执行文本比较;如果第三个参数为0 或者省略执行二进制比较。

Dim MyStr1, MyStr2, MyComp
MyStr1 = "ABCD": MyStr2 = "abcd" ''定义变量。

MyComp = StrComp(MyStr1, MyStr2, 1) '' 返回0。

MyComp = StrComp(MyStr1, MyStr2, 0) '' 返回-1。

MyComp = StrComp(MyStr2, MyStr1) '' 返回1。

9、InStr示例:
下面的示例利用InStr 搜索字符串:
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP"???
SearchChar = "P"??
MyPos = Instr(SearchString, SearchChar)???''返回9.
注意:返回的不是一个字符串在另一个字符串中第一次出现的字符位置,而是字节位置。

10、Split函数示例:
Dim MyString, MyArray, Msg
MyString = "VBScriptXisXfun!"
MyArray = Split(MyString, "x",-1,1)
'' MyArray(0) contains "VBScript".
'' MyArray(1) contains "is".
'' MyArray(2) contains "fun!".
Response.Write(MyArray(0))
11、Replace函数示例:
Replace("ABCD", "BC", "12") ''得到A12D。

相关文档
最新文档