1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > ASP中实现的类似URLEncode的编码函数及对应解码函数

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

时间:2020-04-30 14:13:57

相关推荐

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

下面小编跟大家分享ASP中实现的类似URLEncode的编码函数及对应解码函数,一起来学习下过程究竟如何进行吧!喜欢就赶紧收藏起来哦~

%

'

'All Rights Reserved,[email protected]

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 Code256 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

%

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。