|
字符串操作函数
几个收集或自己写的asp中处理字符串的函数
<% '取字符串长度,汉字算2个字符 function strLength(str) ON ERROR RESUME NEXT dim WINNT_CHINESE WINNT_CHINESE = (len("论坛")=2) if WINNT_CHINESE then dim l,t,c dim i l=len(str) t=l for i=1 to l c=asc(mid(str,i,1)) if c<0 then c=c+65536 if c>255 then t=t+1 end if next strLength=t else strLength=len(str) end if if err.number<>0 then err.clear end function
'显示指定长度的字符串,多于的用省略号表示(中文占2字) function cutStr(str,strlen) dim l,t,c l=len(str) t=0 for i=1 to l c=Abs(Asc(Mid(str,i,1))) if c>255 then t=t+2 else t=t+1 end if if t>=strlen then cutStr=left(str,i)&"..." exit for else cutStr=str end if next cutStr=replace(cutStr,chr(10),"") end function
'显示指定长度的字符串,多于的用省略号表示(中文占1字) Function cutstr(str, length) If Len(str) > length Then cutstr = Left(str, length) & "..." Else cutstr = str End If End Function
'检查文件扩展名,除了允许的其他都拒绝 Function IsExtAllow(extName) Dim i,arrAllowExtName,allowExtName IsExtAllow = false allowExtName = "jpg|gif|bmp"'允许的扩展名
arrAllowExtName = Split(allowExtName,"|") for i=0 to Ubound(arrAllowExtName) if(StrComp(extName,arrAllowExtName(i),1)=0)then IsExtAllow = true end if next End function
'检查文件扩展名,除了拒绝的其他都允许 Function IsExtDeny(extName) Dim i,arrDenyExtName,denyExtName IsExtDeny = true denyExtName = "jpg|gif|bmp"'允许的扩展名
arrDenyExtName = Split(denyExtName,"|") for i=0 to Ubound(arrDenyExtName) if(StrComp(extName,arrDenyExtName(i),1)=0)then IsExtDeny = false end if next End function
'定义获得文件后缀的函数 function GetFileExtName(filename) pos=instrrev(filename,".") if pos>0 then GetFileExtName = mid(filename,pos+1) else GetFileExtName = "" end if end function
'定义获取文件正名的函数 function GetFileName(filename) lens=len(filename)-len(GetFileExtName(filename))-1 GetFileName=left(filename,lens) end function
'随机生成文件名 Function cFileName(FileExtName) cFileName = Year(Date) cFileName = cFileName & Month(Date) cFileName = cFileName & day(Date) cFileName = cFileName & hour(Time) cFileName = cFileName & minute(Time) cFileName = cFileName & second(Time) cFileName = cFileName & "." & FileExtName End function
'================================== '随机生成文件名 '用法: 'For i = 1 to 20 ' Randomize ' x = Int((20 * Rnd) + 1) + 10 ' Response.Write Generator(x) & "<br>" & vbnewline ' Next '================================== Function Generator(Length) dim i, tempS, v dim c(39) tempS = "" c(1) = "a": c(2) = "b": c(3) = "c": c(4) = "d": c(5) = "e": c(6) = "f": c(7) = "g" c(8) = "h": c(9) = "i": c(10) = "j": c(11) = "k": c(12) = "l": c(13) = "m": c(14) = "n" c(15) = "o": c(16) = "p": c(17) = "q": c(18) = "r": c(19) = "s": c(20) = "t": c(21) = "u" c(22) = "v": c(23) = "w": c(24) = "x": c(25) = "y": c(26) = "z": c(27) = "1": c(28) = "2" c(29) = "3": c(30) = "4": c(31) = "5": c(32) = "6": c(33) = "7": c(34) = "8": c(35) = "9" c(36) = "-": c(37) = "_": c(38) = "@": c(39) = "!" If isNumeric(Length) = False Then Response.Write "A numeric datatype was not submitted to this function." Exit Function End If For i = 1 to Length Randomize v = Int((39 * Rnd) + 1) tempS = tempS & c(v) Next Generator = tempS End Function %> 2006-7-18 15:05:31
Posted by jser | 阅读全文() | 回复(0) | 引用通告() | 编辑
|