在VB6.0中怎么实现escape和unescape
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
两套方案,一是调用JAVAscript对象,二是自己写代码编码与解码,代码在CSDN中的以下帖子里贴出:
http://topic.csdn.net/u/20111007/19/83df5464-a787-41de-b435-938aaaed7d4f.html 方案一代码: 复制内容到剪贴板 程序代码 Function Escape(ByVal pstrInput As String) As String Dim objScrCtl As Object Set objScrCtl = CreateObject("MSScriptControl.ScriptControl") objScrCtl.Language = "Javascript" Unescape = objScrCtl.Eval("escape('" & pstrInput & "')") Set objScrCtl = Nothing End Function Function Unescape(ByVal pstrInput As String) As String Dim objScrCtl As Object Set objScrCtl = CreateObject("MSScriptControl.ScriptControl") objScrCtl.Language = "Javascript" Unescape = objScrCtl.Eval("unescape('" & pstrInput & "')") Set objScrCtl = Nothing End Function 方案二代码: 复制内容到剪贴板 程序代码 Function Escape(ByVal Text As String) As String Dim s As String Dim ch As String Dim iAscii As Integer Dim i As Long For i = 1 To Len(Text) ch = Mid$(Text, i, 1) Select Case ch Case "0" To "9", "a" To "z", "A" To "Z", _ "-", "_", ".", "!", "~", "*", "'", "(", ")" s = s & ch Case Else iAscii = AscW(ch) If (0 <= iAscii) And (iAscii < 255) Then s = s & ("%" & Right$("0" & Hex(iAscii), 2)) Else s = s & ("%u" & Right$("000" & Hex(iAscii), 4)) End If End Select Next Escape = s End Function Function Unescape(ByVal Text As String) As String Dim i As Long For i = 1 To Len(Text) If Mid$(Text, i, 2) = "%u" Then Text = Replace$(Text, Mid$(Text, i, 6), ChrW$(AscW(ChrW$("&H" & Mid$(Text, i + 2, 4))))) If Mid$(Text, i, 1) = "%" Then Text = Replace$(Text, Mid$(Text, i, 3), Chr$(Asc(Chr$("&H" & Mid$(Text, i + 1, 2))))) Next i Unescape = Text End Function 该文章在 2013/12/11 14:48:41 编辑过 |
关键字查询
相关文章
正在查询... |