ASP中实现的类似URLEncode的编码函数及对应解码函数

王朝asp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

<%

'Coding.inc.asp

'All Rights Reserved, Room3rd@hotmail.com

Function Encode(Str)

Dim Count, Pos, Ch, Code

Dim SweetCh

'SweetCh中表示不需要进行编码的字符

SweetCh = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_{}[]()"

Encode = ""

Count = Len(Str)

Pos = 1

Do While Pos<=Count

Ch = Mid(Str, Pos, 1)

Code = Asc(Ch)

If Code>=0 And Code<256 Then '汉字不予处理

If Ch<>"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos<=Count

Ch = Mid(Str, Pos, 1)

If Ch="%" Then

If Pos+2<=Count Then

Ch = Chr((InStr("0123456789ABCDEF", UCase(Mid(Str, Pos+1, 1)))-1) * 16 + InStr("0123456789ABCDEF",UCase(Mid(Str, Pos+2, 1))) - 1)

Else

'编码串不正确

Ch = ""

End If

Pos = Pos + 2

End If

Decode = Decode & Ch

Pos = Pos + 1

Loop

End Function

%>=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos=0 And Code"%" Then

If InStr(SweetCh, Ch)=0 Then

Ch = "%" & Right("0" & Hex(Code), 2)

End If

Else

Ch = "%25"

End If

End If

Encode = Encode & Ch

Pos = Pos + 1

Loop

End Function

Function Decode(Str)

Dim Count, Pos, Ch, Code

Decode = ""

Count = Len(Str)

Pos = 1

Do While Pos

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航