有风无度
XfengNet.COM
自己写的几个有用的函数
The Articles Title
’------------------------------------------------------
’函数名:doWrite(str)
’作 用:打印输出
’参 数:str/字符串
’返回值:无
’-------------------------------------------------------
Public Function doWrite(str)
Response.Write(str)
End Function
’-------------------------------------------------------
’函数名:Crypt(texti,salasana)
’作 用:简单字符串加密
’参 数:texti/加密字符串,salasana/特征码
’返回值:加密字符串
’-------------------------------------------------------
Function Crypt(texti,salasana)
Dim t, x1, g, tt
Dim sana
Dim Crypted
For t = 1 To Len(salasana)
sana = Asc(Mid(salasana, t, 1))
x1 = x1 + sana
Next
x1 = Int((x1 * 0.1) / 6)
salasana = x1
g = 0
For tt = 1 To Len(texti)
sana = Asc(Mid(texti, tt, 1))
g = g + 1
If g = 6 Then g = 0
x1 = 0
If g = 0 Then x1 = sana - (salasana - 2)
If g = 1 Then x1 = sana + (salasana - 5)
If g = 2 Then x1 = sana - (salasana - 4)
If g = 3 Then x1 = sana + (salasana - 2)
If g = 4 Then x1 = sana - (salasana - 3)
If g = 5 Then x1 = sana + (salasana - 5)
x1 = x1 + g
Crypted = Crypted & Chr(x1)
Next
Crypt = Crypted
End Function
’-------------------------------------------------------
’函数名:DeCrypt(texti,salasana)
’作 用:简单字符串解密
’参 数:texti/加密字符串,salasana/特征码
’返回值:解密字符串
’-------------------------------------------------------
Function DeCrypt(texti,salasana)
Dim t, sana, x1, g, tt
Dim decrypted
For t = 1 To Len(salasana)
sana = Asc(Mid(salasana, t, 1))
x1 = x1 + sana
Next
x1 = Int((x1 * 0.1) / 6)
salasana = x1
g = 0
For tt = 1 To Len(texti)
sana = Asc(Mid(texti, tt, 1))
g = g + 1
If g = 6 Then g = 0
x1 = 0
If g = 0 Then x1 = sana + (salasana - 2)
If g = 1 Then x1 = sana - (salasana - 5)
If g = 2 Then x1 = sana + (salasana - 4)
If g = 3 Then x1 = sana - (salasana - 2)
If g = 4 Then x1 = sana + (salasana - 3)
If g = 5 Then x1 = sana - (salasana - 5)
x1 = x1 - g
decrypted = decrypted & Chr(x1)
Next
DeCrypt = decrypted
End Function
’*************************************************
’作 用:格式化text的内容
’函数名:FormatStr(fString)
’参 数:fString ---- 字符串
’*************************************************
Function FormatStr(fString)
on error resume next
if fString<> and not isnull(fString) then
fString = replace(fString, >, >)
fString = replace(fString, <, <)
fString = Replace(fString, CHR(32), )
fString = Replace(fString, CHR(9), )
fString = Replace(fString, CHR(34), )
fString = Replace(fString, CHR(39), )
fString = Replace(fString, CHR(10) & CHR(10),
)
fString = Replace(fString, CHR(10),
)
FormatStr=fString
else
FormatStr=
end if
End Function
’*************************************************
’作 用:反向格式化text的内容
’函数名:UnFormatStr(fString)
’参 数:fString ---- 字符串
’*************************************************
Function UnFormatStr(fString)
if fString<> and not isnull(fString) then
fString = replace(fString, >, >)
fString = replace(fString, <, <)
fString = Replace(fString, , CHR(13))
fString = Replace(fString,
, CHR(10) & CHR(10))
fString = Replace(fString,
, CHR(10))
fString = Replace(fString, , chr(32))
UnFormatStr=fString
else
UnFormatStr=
end if
End Function
Function setConnDB()’链接数据库
Dim strConn,dbPath,initPath,dbName
initPath = /Vhost/ceshi/DataBase/
dbName = DB_%XfengNet_DB%.mdb
dbPath = initPath&dbName
strConn = driver={Microsoft Access Driver (*.mdb)};dbq=&Server.MapPath(dbPath)
’strConn = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&Server.MapPath(dbPath)
Set conn = Server.CreateObject(ADODB.Connection)
conn.Open strConn
Set setConnDB = conn
If Err Then
Err.Clear
conn.Close
Set conn = nothing
Response.Write(数据库连接失败)
Response.End()
End If
End Function
Function setCloseConn()’关闭数据库
conn.Close
Set conn = Nothing
End Function
’-------------------------------------------------------
’函数名:getRequestURL(key)
’作 用:获取伪静态URL参数值
’参 数:key/关键字
’返回值:字符串/数值
’实 例:act-List-cid-138-page-12-view.html
’-------------------------------------------------------
Function getRequestURL(key)
Dim strURL,strRep,arrURL
getRequestURL =
strRep = .html
strURL = Lcase(Request.ServerVariables(QUERY_STRING))
’strURL = Lcase(Request.QueryString())
strURL = Replace(strURL,strRep,)
strURL = Replace(Replace(strURL,/,-),.,-)’附加格式
strURL = Replace(Replace(strURL,&,-),=,-)’附加格式
If InStr(strURL,key&-)>0 Then
arrURL = Split(strURL,-)
For i=LBound(arrURL) to UBound(arrURL)
If arrURL(i)=key Then
getRequestURL = arrURL(i+1)
Exit For
End If
Next
End If
End Function
’-------------------------------------------------------
’函数名:getRequestURLkey()
’作 用:获取伪静态URL标识符
’参 数:无
’返回值:字符串
’实 例:act-List-cid-138-page-12-view.html
’-------------------------------------------------------
Function getRequestURLkey()
Dim strURL,strRep,arrURL
getRequestURLkey =
strRep = .html
strURL = Lcase(Request.ServerVariables(QUERY_STRING))
’strURL = Lcase(Request.QueryString())
strURL = Replace(strURL,strRep,)
strURL = Replace(Replace(strURL,/,-),.,-)’附加格式
strURL = Replace(Replace(strURL,&,-),=,-)’附加格式
If InStr(strURL,-)>0 Then
arrURL = Split(strURL,-)
getRequestURLkey = arrURL(UBound(arrURL))
End If
End Function
’-------------------------------------------------------
’函数名:UnURLEncode(str)
’作 用:Server.URLEncode()的URL解码
’参 数:str/字符串
’返回值:字符串
’-------------------------------------------------------
Function UnURLEncode(str)
Dim strNew,havechar,lastchar,char_c,next_c,next_n
strNew =
havechar = False
lastchar =
For i=1 to Len(str)
char_c = mid(str,i,1)
If char_c=+ Then
strNew = strNew &
ElseIf char_c=% Then
next_c = mid(str,i+1,2)
next_n = CInt(&h & next_c)
If havechar Then
havechar = False
strNew = strNew & Chr(CInt(&h&lastchar&next_c))
Else
If Abs(next_n)<=127 Then
strNew = strNew & Chr(next_n)
Else
havechar = True
lastchar = next_c
End If
End If
i = i + 2
Else
strNew = strNew & char_c
End If
Next
UnURLEncode = strNew
End Function
Author:xfengnet
Hits()
2011-04-29 13:17:41
推选文章