[Visual Basic] 纯文本查看 复制代码
'函数是从@乱码师傅那盗取过来的 嘿嘿O(∩_∩)O~、
'Eval声明
Function Eval(ByVal Expressions As String) As Double
Set Mssc = CreateObject("MSScriptControl.ScriptControl")
Mssc.Language = "vbscript"
Eval = Mssc.Eval(Expressions)
End Function
Function URLEncode(strURL) '编码
Dim I
Dim tempStr
For I = 1 To Len(strURL)
If Asc(Mid(strURL, I, 1)) < 0 Then
tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, I, 1)))), 2)
tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, I, 1)))), Len(CStr(Hex(Asc(Mid(strURL, I, 1))))) - 2) & tempStr
URLEncode = URLEncode & tempStr
ElseIf (Asc(Mid(strURL, I, 1)) >= 65 And Asc(Mid(strURL, I, 1)) <= 90) Or (Asc(Mid(strURL, I, 1)) >= 97 And Asc(Mid(strURL, I, 1)) <= 122) Or (Asc(Mid(strURL, I, 1)) >= 48 And Asc(Mid(strURL, I, 1)) <= 57) Then
URLEncode = URLEncode & Mid(strURL, I, 1)
Else
URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, I, 1)))
End If
Next
End Function
Function URLDecode(strURL) '解码
Dim I
If InStr(strURL, "%") = 0 Then
URLDecode = strURL
Exit Function
End If
For I = 1 To Len(strURL)
If Mid(strURL, I, 1) = "%" Then
If Eval("&H" & Mid(strURL, I + 1, 2)) > 127 Then
URLDecode = URLDecode & Chr(Eval("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
I = I + 5
Else
URLDecode = URLDecode & Chr(Eval("&H" & Mid(strURL, I + 1, 2)))
I = I + 2
End If
Else
URLDecode = URLDecode & Mid(strURL, I, 1)
End If
Next
End Function
'=========================
'调用
Text2.Text = URLEncode(Text1.Text)
Text2.Text = URLDecode(Text1.Text)